I added a feature to my code, but when I run all the test, all the test runs successfully, but Jest still throws an internal error with this message:
Ran all test suites.
the_path\node_modules\expect\build\index.js:303
throw error;
^
JestAssertionError: expect(received).toBe(expected) // Object.is equality
Expected: "node-user-settings"
Received: "null"
I created another .js file and called the code I wanted to test with Jest and it runs properly. Now, I don't understand why Jest throws an internal error.
This is the test that generates the error.
test("asynchronously gets a value, using callbacks without optional filename", () => {
settings.getState_c("moduleName", null, null, (err, data) => {
expect(err).toBe(null);
expect(data).toBe("node-user-settings");
});
});
CodePudding user response:
I think you need to tell Jest that you're testing an asynchronous function: https://jestjs.io/docs/asynchronous.
Use done
instead of async
if your function does not return a Promise, but is asynchronous.