Jest: @jest-environment node not working

Created on 5 Jul 2018  路  3Comments  路  Source: facebook/jest

馃悰 Bug Report

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".

To Reproduce

  1. Create a js file to be tested like this:
console.log(typeof window);
export const URL = typeof window === 'undefined' ? process.env.BASE_URL || ('http://localhost:8080') : '';
  1. Create a test file that imports the file to be tested, like:
/**
* @jest-environment node
*/
import { URL } from './config';

describe('Config on NodeJS environment', () => {
  test('it should be a relative url', () => {
    expect(URL).toBeFalsy();
  });
});
  1. running the test don't mind about the result, just check what console.log is writing

Expected behavior

console.log should write undefined

Run npx envinfo --preset jest

Paste 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

Most helpful comment

I deleted node_modules and reinstalled everything and now it works 馃憤

All 3 comments

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_

Was this page helpful?
0 / 5 - 0 ratings