Skip to content
This repository was archived by the owner on Jan 26, 2019. It is now read-only.
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

jest testing is not using config/polyfills.js #136

Closed
@cyyyu

Description

@cyyyu

Hi, here I encountered a issue which is about testing.

Briefly: in a ejected project, jest is not using config/polyfills.js as its setupFiles, even it has been specified in package.json.

Steps to Reproduce

  1. generate a new project with create-react-app-typescript
  2. do yarn eject
  3. add window.anything = 'test' to config/polyfills.js
  4. add expect(window.anything).toBe('test') to src/App.test.tsx
  5. run test

Then it failed. See outputs below.

 FAIL  src/App.test.tsx
  ● renders without crashing

    expect(received).toBe(expected)

    Expected value to be (using ===):
      "string"
    Received:
      undefined

    Difference:

      Comparing two different types of values. Expected string but received undefined.

      at Object.<anonymous> (src/App.test.tsx:9:27)
          at Promise (<anonymous>)
      at Promise.resolve.then.el (node_modules/p-map/index.js:42:16)
          at <anonymous>

  ✕ renders without crashing (306ms)

I could only reproduce it in a create-react-app-typescript project, while create-react-app projects worked fine.
I also did the same in a create-react-app project, and I got the expected outputs.

 PASS  src/App.test.js
  ✓ renders without crashing (19ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.163s
Ran all test suites related to changed files.

Please advise. thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions