You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the jest.mock('module'); feature to deep auto-mock an entire module, an error is thrown if the module contains any objects that contain functions with a numeric name.
To Reproduce
Example library kafkajs
require(`kafkajs`)jest.mock('kafkajs');
Expected behavior
The library should be mocked with no issues.
Actual behaviour
Application exits with the following error thrown:
FAIL tests/unit/mock.test.js
● Test suite failed to run
SyntaxError: Unexpected number
at new Function (<anonymous>)
Best handling is probably prefix a $ or something, like we do with other invalid function names. I'll work on a fix for this.
Note that in our case, rather than new Function(1, {}), it's something like
newFunction('mockConstructor','return function 1() {return mockConstructor.apply(this,arguments);}')
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
🐛 Bug Report
When using the jest.mock('module'); feature to deep auto-mock an entire module, an error is thrown if the module contains any objects that contain functions with a numeric name.
To Reproduce
Example library
kafkajs
Expected behavior
The library should be mocked with no issues.
Actual behaviour
Application exits with the following error thrown:
Which is caused by the following line in jest-mock/index.js (https://github.com/facebook/jest/blob/master/packages/jest-mock/src/index.js#L647)
the error is a standard nodejs error which can be emulated in the repl via
Due to
new Function()
throwingUnexpected number
if a numeric value is passed to it.Offending object with numeric function names in
kafkajs
library can be found here:https://github.com/tulios/kafkajs/blob/master/src/protocol/message/compression/index.js#L14
Run
npx envinfo --preset jest
Paste the results here:
The text was updated successfully, but these errors were encountered: