test: add test to check that you can set the env from window object

This commit is contained in:
Matthew Russell
2023-06-23 15:41:28 -07:00
parent 251d0369ca
commit 9aaaec779e
2 changed files with 20 additions and 1 deletions
@@ -301,6 +301,25 @@ describe('useEnvironment', () => {
expect(fetch).toHaveBeenCalledWith(configUrl);
});
it('uses env vars from window._env_ if set', async () => {
const url = 'http://foo.bar.com';
// @ts-ignore _env_ is declared in app
window._env_ = {
VEGA_URL: url,
};
const { result } = setup();
await act(async () => {
result.current.initialize();
});
expect(result.current.VEGA_URL).toBe(url);
// @ts-ignore delete _env_
delete window['_env_'];
});
it('sets error if environment is invalid', async () => {
const error = console.error;
console.error = noop;
@@ -412,5 +412,5 @@ export function windowOrDefault(key: string, defaultValue?: string) {
return window._env_[key];
}
}
return defaultValue || '';
return defaultValue || undefined;
}