Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@jest-environment node not working #6634

Closed
StefanoSega opened this issue Jul 5, 2018 · 4 comments
Closed

@jest-environment node not working #6634

StefanoSega opened this issue Jul 5, 2018 · 4 comments

Comments

@StefanoSega
Copy link

🐛 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
@thymikee
Copy link
Collaborator

thymikee commented Jul 5, 2018

Cannot repro: https://repl.it/repls/WellmadeGummyParticle
If you're using CRA, this is not supported, as they're still on Jest 20.

@thymikee thymikee closed this as completed Jul 5, 2018
@StefanoSega
Copy link
Author

I deleted node_modules and reinstalled everything and now it works 👍

@thymikee
Copy link
Collaborator

thymikee commented Jul 6, 2018

classic

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants