jest
jest copied to clipboard
automock is crashing
🐛 Bug Report
When setting in jest.config.js
property automock: true
the tests run is crashing with error
>npx jest
FAIL ./index.test.js
× (30ms)
●
TypeError: Cannot destructure property 'formatters' of 'module.exports' as it is undefined.
> 1 | require('dotenv-parse-variables')
| ^
2 |
at Object.<anonymous> (node_modules/debug/src/node.js:238:8)
at Object.<anonymous> (index.js:1:1)
at Object.<anonymous> (index.test.js:4:3)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 2.893s, estimated 4s
Ran all test suites.
To Reproduce
Consider two files:
index.js
require('dotenv-parse-variables')
index.test.js
jest.unmock('./index')
test('', () => {
require('./index')
})
Steps to reproduce the behavior:
run npx jest
Expected behavior
Jest should not crash
Link to repl or repo (highly encouraged)
https://github.com/Alexsey/jest-automock-crash
envinfo
>npx envinfo --preset jest
npx: installed 1 in 2.334s
System:
OS: Windows 10 10.0.18362
CPU: (4) x64 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
Binaries:
Node: 13.7.0 - C:\Program Files\nodejs\node.EXE
npm: 6.13.6 - C:\Program Files\nodejs\npm.CMD
npmPackages:
jest: ^25.1.0 => 25.1.0
I was able to reproduce this issue and appears the problem is with mocking modules that return a method.
Here is a simple example:
//my-module
function setup() {
return {
stuff: 'it'
};
}
module.exports = setup;
With mocking, require('./my-module')()
will return undefined
.
That specific issue is from the debug
package internally expecting a specific object after calling the method from the export.
I'm also seeing this issue from the debug
package. Do you know of any fix or workaround?
I'm having the same error when using automock true. Is this still an unresolved issue?
this is actually a major issue - i've just been spending hours trying to figure out why automocking is failing using jest.mock('my_node_module_name');
when automocking a class accessing ClassName.mock.instances[0]
returns an empty object.
I tried debugging by creating a custom mock in mocks with the same name as the node_modules library and im receiving TypeError: Cannot destructure property 'formatters' of 'module.exports' as it is undefined.
error.
It seems that these might be related?
i didnt receive this error until I added automock: true
to jest config json file as files in mocks werent creating an automock - they were failing silently.
This hasnt been picked up in months and renders this package pretty defunct for our integration tests. Any news on an update or fix?
looks like this links to #6127
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.
Still relevant
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.
Still relevant