Jest: test.each(...) is not a function in Jest 23.2

Created on 4 Jul 2018  ·  10Comments  ·  Source: facebook/jest

🐛 Bug Report

test.each() doesn't exist in tests using Jest 23.2 and Angular 6 with jest-preset-angular.

To Reproduce

  1. Create Angular project using @angular/cli in version 6.0.8.
  2. Add [email protected] [email protected] @types/[email protected].
  3. In package.json add jest settings:
"jest": {
    "preset": "jest-preset-angular",
    "setupTestFrameworkScriptFile": "<rootDir>/src/setupJest.ts",
    "collectCoverage": true,
    "coverageReporters": [
      "html"
    ]
  }
  1. in src directory add setupJest.ts:
import 'jest-preset-angular';

Error['stackTraceLimit'] = 4;
  1. test.each() in test.

Expected behavior

test.each() should run tests by passed cases.

Link to repl or repo (highly encouraged)

Please provide either a repl.it demo or a minimal repository on GitHub.

Issues without a reproduction link are likely to stall.

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: Linux 4.15 Ubuntu 18.04 LTS (Bionic Beaver)
    CPU: x64 Intel(R) Core(TM) i5-4460  CPU @ 3.20GHz
  Binaries:
    Node: 8.11.1 - /usr/local/bin/node
    npm: 6.0.1 - /usr/local/bin/npm
  npmPackages:
    @types/jest: 23.1.4 => 23.1.4 
    jest: ^23.2.0 => 23.2.0 

Most helpful comment

@thymikee I have the same problem and I am using react.

All 10 comments

This issue belongs to jest-preset-angular.

@thymikee I have the same problem and I am using react.

@janis91 are you using create React app? I don’t believe it is using Jest@23 yet. You can install jest-each manually to use it in the meantime.

@mattphillips well, yes. and you're right. I just wanted to make sure, that this isn't really belonging to jest-preset-angular alone. I think there are more projects with this issue when it comes to jest@23. I will give jest-each a try though. Thanks

manually installing jest-each did not work for me

@leojh when you manually install jest-each it has a different syntax to test.each, instead you import it in your test file and use it like:

import each from 'jest-each';

each([1, 2, 3]).test('%s should be greater than zero', value => expect(value).toBeGreaterThan(0));

See the docs here: https://github.com/facebook/jest/tree/master/packages/jest-each

any progress on this? (using 23.6)

@thymikee Plz reopen - I can confirm this in React with Jest 23.6.0

@dmwelch jest-each has been part of all releases in Jest since Jest@23. Here's the release for the 23.6 version: https://www.npmjs.com/package/jest-each/v/23.6.0. I actually still use Jest 23.6.0 for quite a few projects and have no issues with this.

Are you able to create a small repo with the issue? I suspect that it may just be a config issue i.e. installing Jest@22 🤷‍♂️

That was my first thought, so I checked my jest version in package.json:

"jest": "23.6.0",

No cigar there, but my jest-cli is installed at "~22.4.2" - doesn't seem like that should make a difference. I'll work on a test repo tomorrow, if I can get around to it. Cheers!

Was this page helpful?
0 / 5 - 0 ratings