Skip to content

Instantly share code, notes, and snippets.

@DiegoVictor
Created January 31, 2022 22:46
Show Gist options
  • Save DiegoVictor/5dc4f7210426a95f2bad26e7dfb66f1d to your computer and use it in GitHub Desktop.
Save DiegoVictor/5dc4f7210426a95f2bad26e7dfb66f1d to your computer and use it in GitHub Desktop.
Example code to run Jest from a Node.js script.
const sum = (n, m) => n + m;
module.exports = { sum };
const { sum } = require("funcs");
describe("Sum", () => {
it("should be able to sum numbers", async () => {
expect(sum(2, 2)).toBe(4);
});
it("should be able to sum negative numbers", async () => {
expect(sum(-2, 2)).toBe(0);
});
});
const { runCLI } = require("jest");
runCLI(
{
collectCoverage: true,
collectCoverageFrom: "./*.js",
coveragePathIgnorePatterns: ["./main.js"],
},
[""]
);
{
"dependencies": {
"jest": "^27.4.5"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment