This is for Jest 28.1.1. You can see the problem when doing the example demo with sum(); this is with TypeScript so ts-jest (v28.0.4) is also involved if that makes a difference.
// x.ts
export function sum(a :number, b :number) :number {
return a + b;
}
Then the tests/x.test.ts is
import * as x from "../x";
describe("app tests", () => {
test('app function1 function', () => {
expect(x.sum(2,2)).toBe(4);
try { // test for throw
expect(x.sum(2,2)).toBe(5); // should fail
} catch (error:any) {
console.log("===============catch: " + error + "===============");
}
expect(x.sum(2,2)).toBe(6); // should fail
expect(x.sum(2,2)).toBe(7); // should fail
});
});
The reason for the test to begin with was to verify it would show multiple failures, but it will only show the first. Eventually I added the try/catch just to see if there was a throw I was unaware of and I found it was happening! When I run "npm test" (which runs "jest --coverage" from my package.json) I get:
console.log
===============catch: Error: expect(received).toBe(expected) // Object.is equality
Expected: 5
Received: 4===============
at Object.<anonymous> (src/data/tests/x.test.ts:10:21)
Why is toBe() throwing an error? My code is not doing the throw. How do I make it not do that? Is there a configuration affecting this I haven't found"
I want it to show me 1 pass and 3 fails, but a throw from somewhere is preventing that and I can't find anything about this in the docs or in the github issues.
