ð jest
module.exports = {
extends: ["@aiou"],
overrides: {
env: {
jest: true
}
}
};
const ERROR_CODE = jest
.spyOn<any, any>(process, "exit")
.mockImplementation(() => {});
func();
expect(ERROR_CODE).toHaveBeenCalledWith(1);
npm
jest path/file
åŠæ `jest`
æ¯ `npm script`
{
"test": "jest"
}
å¯ä»¥éè¿ `npm run test -- path/file`
pnpm
`pnpm run test -- -- path/file`
isArray
expect(Array.isArray([])).toBe(true);
match value
expect(func()).toEqual(["a"]);
scannner = {
scan() {
console.log("/user/jiangweixian");
}
};
console.log
it("debug should be called", async () => {
console.log = jest.fn();
// in scanner.scan will exec console.log
await scanner.scan("/user/jiangweixian");
expect(console.log).toHaveBeenCalledWith("/user/jiangweixian");
});
/**
* @jest-environment node
*/
ååš`*.test.ts`
倎éšïŒäœäžºæ³šéå°±è¡ã
å¯ä»¥è§£å³äžäºè¯·æ±çè·šåé®é¢