Created
January 31, 2022 22:46
-
-
Save DiegoVictor/5dc4f7210426a95f2bad26e7dfb66f1d to your computer and use it in GitHub Desktop.
Example code to run Jest from a Node.js script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sum = (n, m) => n + m; | |
module.exports = { sum }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { runCLI } = require("jest"); | |
runCLI( | |
{ | |
collectCoverage: true, | |
collectCoverageFrom: "./*.js", | |
coveragePathIgnorePatterns: ["./main.js"], | |
}, | |
[""] | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"jest": "^27.4.5" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment