27

Option "setupTestFrameworkScriptFile" was replaced by configuration "setupFilesAfterEnv", which supports multiple paths.

Please update your configuration.

I found this exact question here: setupTestFrameworkScriptFile is not supported error

I renamed my jest.config.js to setUpTests.js however that did not remove the deprecated error warning.

import { configure } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'

configure({ adapter: new Adapter() })

package.json scripts

"scripts": {
  "dev": "next -p 7777",
  "build": "next build",
  "start": "next -p 7777",
  "test": "NODE_ENV=test jest --watch --no-cache",
  "test-win": "SET NODE_ENV=test&& jest --watch"
}
"@types/enzyme": "^3.1.15",
"@types/jest": "^23.3.13",
"jest": "^24.1.0"
Community
  • 1
  • 1
Leon Gaban
  • 36,509
  • 115
  • 332
  • 529

5 Answers5

46

Jest used to have a config option called setupTestFrameworkScriptFile...

...but it was deprecated in favor of the newer setupFilesAfterEnv in PR #7119 which shipped with version 24.0.0.

Since you are using Jest ^v24.1.0 you will need to use setupFilesAfterEnv.

Just find where setupTestFrameworkScriptFile is used in your Jest config, rename it to setupFilesAfterEnv, and put the single file it used to point to in an array and you should be good to go.

Example, change this jest.config.js:

module.exports = {
  ...
  setupTestFrameworkScriptFile: './setup.js',
  ...
}

...to this:

module.exports = {
  ...
  setupFilesAfterEnv: ['./setup.js'],
  ...
}
Brian Adams
  • 43,011
  • 9
  • 113
  • 111
7

If you are using create-react-app, change the key name at package.json file

from

  "jest": {
    // ...
    "setupTestFrameworkScriptFile": "<rootDir>/src/setupTests.js",

to

  "jest": {
    // ...
    "setupFilesAfterEnv": ["<rootDir>/src/setupTests.js"],
Eric
  • 73
  • 1
  • 3
0

After I changed my file name from setupTests.js to setup.tests.js it worked. Maybe the dir path name did not match. Make sure you check that!

peanutz
  • 346
  • 3
  • 6
0

In my case in 'jest.config.js' I had

setupFilesAfterEnv: ['<rootDir>/setup-jest.ts']

correctly referencing 'setup-jest.ts' in <rootDir>. After renaming the file itself and the reference to it from

setup-jest.ts

to

setupJest.js

the error message vanished. Weird. Seems as if the hyphen in the file-name or being the same as in 'node_modules.jest-reset-angular.setup-jest.js' was the culprit. Using Angular 13 and Jest (in package.json):

"jest": "^28.1.0",

"jest-preset-angular": "^12.1.0",

I'm on Lubuntu 22.04.

wbartussek
  • 1,850
  • 1
  • 10
  • 8
0

Jest message is not mantained anymore: https://github.com/mattphillips/jest-expect-message/issues

So I suggest using:

const msg = '... my message...'
expect({msg, result}).toEqual({msg, result: expected})

From https://github.com/facebook/jest/issues/3293

Or alternatively

function expectToBeTrue(result: any, message: string){
    return expect({message, result}).toBe({message, result: true})
}


expectToBeTrue(compute() == 1, "Oh no compute should return 1!")
Tomas G.
  • 3,784
  • 25
  • 28