jest
jest copied to clipboard
[Bug]: it.each doesn't support BigInt, complaining "TypeError: Do not know how to serialize a BigInt"
Version
28.0.2
Steps to reproduce
Following test will end up with an error (see section "Action Behaviour"), no matter the matcher is passed or failed.
describe("error", () => {
it.each([
[1n, 2n, 3n]
])("test", (a, b, c) => {
expect(a + b).toBe(c);
});
});
Also, Jest prints out such error whenever a test is failed (without it.each).
describe("error", () => {
it("print annoying message when a test failed.", () => {
expect(1n + 3n).toBe(10n);
});
});
But oddly, if you write matcher outside it(...)
functions, Jest will not print out the error message - it will print out messages of failed tests:
describe("write matcher outside it(...)", () => {
expect(1n + 3n).toBe(10n);
});
● Test suite failed to run
expect(received).toBe(expected) // Object.is equality
Expected: 10n
Received: 4n
12 |
13 | describe("write matcher outside it(...)", () => {
> 14 | expect(1n + 3n).toBe(10n);
| ^
15 | });
at toBe (chapter.16-greedy-algorithm/exercises/__tests__/16.2-7.js:14:21)
at describe (chapter.16-greedy-algorithm/exercises/__tests__/16.2-7.js:13:1)
Expected behaviour
This error should not shows up.
Actual behavior
Complained that:
● Test suite failed to run
TypeError: Do not know how to serialize a BigInt
at stringify (<anonymous>)
at messageParent (node_modules/jest-worker/build/workers/messageParent.js:33:19)
Additional context
No response
Environment
System:
OS: Windows 10 10.0.19042
CPU: (4) x64 Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
Binaries:
Node: 16.14.2 - C:\Program Files\nodejs\node.EXE
Yarn: 1.13.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 8.5.0 - C:\Program Files\nodejs\npm.CMD
npmPackages:
jest: ^28.0.2 => 28.0.2
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
Dear, I would like to take it.
I think upgrade the jest
version to the latest and this issue can be solved now. I have tried in my mac, and now it currently can run correctly.
Environment
System:
OS: Apple OX 13.2.1
CPU: Apple M1 Max
Binaries:
Node: 16.4.1
Yarn: 1.22.19
npm: 9.8.1
jest: 29.3
I'm currently developing using NestJS, and when I encountered this issue, I looked it up and found this
I was able to solve it from the following site: https://zenn.dev/serinuntius/scraps/02dfe48b643745
jest.config.ts
"workerThreads": true
I'm not using jest.config.ts, so I just added that code to the jest part of my package.json and that solved it. I'm not sure why this solves it, though, so if anyone knows how, I'd appreciate a reply.