Related to #5119
Decorating my test file with @jest-environment node on top of it doesn't work and typeof window returns "object" instead of "undefined".
console.log(typeof window);
export const URL = typeof window === 'undefined' ? process.env.BASE_URL || ('http://localhost:8080') : '';
/**
* @jest-environment node
*/
import { URL } from './config';
describe('Config on NodeJS environment', () => {
test('it should be a relative url', () => {
expect(URL).toBeFalsy();
});
});
console.log is writingconsole.log should write undefined
npx envinfo --preset jestPaste the results here:
System:
OS: macOS High Sierra 10.13.5
CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Binaries:
Node: 8.11.1 - /usr/local/bin/node
npm: 5.6.0 - /usr/local/bin/npm
npmPackages:
jest: ^23.3.0 => 23.3.0
Cannot repro: https://repl.it/repls/WellmadeGummyParticle
If you're using CRA, this is not supported, as they're still on Jest 20.
I deleted node_modules and reinstalled everything and now it works 馃憤
_classic_
Most helpful comment
I deleted
node_modulesand reinstalled everything and now it works 馃憤