Jest: @jest-environment jsdom not working

Created on 11 Apr 2017  路  6Comments  路  Source: facebook/jest

I'd like to report a bug.

What is the current behavior?
When setting the jest environment to node in the package.json and using the @jest-environment jsdom docblock in a UI test, jsdom is not available.

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.
https://github.com/sleepingevil/jest-env-bug

What is the expected behavior?
Jest should set up the jsdom environment for the tests that use the above mentioned docblock.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Jest configuration can be found in the provided repo. I'm using node 6.9.2, npm 3.10.9 and yarn 0.19.1. I'm on MacOS Sierra 10.12.4.

Most helpful comment

This works but only on the top level, not for individual tests. This annotation needs to go on the top of your file and works for the entire suite.

All 6 comments

This feature hasn't been shipped yet. It will ship in about a month.

Thanks for the quick response and the clarification. I expected it to work, because I found it in the documentation: https://facebook.github.io/jest/docs/configuration.html#testenvironment-string

Ah, would you mind sending us a PR that adds "available in 20.0.0" just like we do in other parts of the docs? :)

Not working with Jest 20.0.4

If I run jest command without argument :

````javascript
/* eslint-disable import/no-extraneous-dependencies */
import React from 'react';
import { shallow } from 'enzyme';

import HomeRoute from '../HomeRoute';

describe('', () => {
/**

  • @jest-environment node
    */
    test('renders', () => {
    console.log(typeof window);// object
    const wrapper = shallow();
    expect(wrapper).toMatchSnapshot();
    });
    });
    ``` console.logshould returnsundefined` in node environment

If I run same test with flag --env=node

console.log returns undefined

EDIT

https://github.com/facebook/jest/issues/4024

If iI put comment in the very begining of my file it's working.

Is there any chance to get this feature works on a per-test ?

This works but only on the top level, not for individual tests. This annotation needs to go on the top of your file and works for the entire suite.

Was this page helpful?
0 / 5 - 0 ratings