Leon Gaban
Leon Gaban

Reputation: 39044

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

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"

Upvotes: 28

Views: 19802

Answers (5)

Tomas Giro
Tomas Giro

Reputation: 4267

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!")

Upvotes: 0

wbartussek
wbartussek

Reputation: 2028

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.

Upvotes: 0

peanutz
peanutz

Reputation: 516

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!

Upvotes: 0

Eric
Eric

Reputation: 73

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"],

Upvotes: 7

Brian Adams
Brian Adams

Reputation: 45840

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'],
  ...
}

Upvotes: 48

Related Questions