但有的时候,time是动态生成的,比如fetchConfig中的time 改成new Date(), 每一次跑单元测试的时候,time 都不一样,jest肯定报错。这时可以给toMatchSnapshot() 方法传递一个参数{ time: expect.any(Date) 表示什么时间都可以,就不要匹配时间了。 test('fetch config', () =>{ expect(fetchConfig).toMatchSna...
expect(generateConfig()).toMatchInlineSnapshot( { time: expect.any(Date) }, ); }); 1. 2. 3. 4. 5. 6. 7. 8. 第一次执行之后 test("测试generateConfig", () => { // 匹配快照 expect(generateConfig()).toMatchInlineSnapshot( { time: expect.any(Date) }, // 执行test生成的快照 ...
time: expect.any(Date) }) }) 1. 2. 3. 4. 5. 内联快照 内联快照-不会生成新的快照文件,而是将快照内容写入当前执行测试的文件中 其中在生成内联快照的时候需要第三方的包prettier配合 test('test config snapshot', () => { expect(generateConfig()).toMatchInlineSnapshot({ time: expect.any(Date...
expect(2+2).toBe(4); expect(data).toEqual({one:1, two:2}); 判断浮点数:toBeCloseTo expect(value).toBeCloseTo(0.3); 判断异常:toThrow expect(compileAndroidCode).toThrow(ConfigError); 3.2.异步测试:回调函数、Promise 、async函数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19...
test("测试 generateConfig", () => { expect(generateConfig()).toMatchSnapshot({ date: expect.any(Date) }); }); 行内快照 上述的快照是在 __snapshots__ 文件夹下生成的,还有一种方式是通过 toMatchInlineSnapshot 在当前的 .test.js 文件中生成。需要注意的是,这种方式通常需要配合 prettier 工具...
expect(a).toThrow(/this is a new error/); // expect(a).not.toThrow(); // 没有抛出异常 }) 其他 【 any 】... 2. hook 钩子函数 beforeAll/afterAll/beforeEach/afterEach 代码语言:txt 复制 beforeAll(() => { console.log('beforeAll') ...
console, decodeURI, decodeURIComponent, encodeURI, encodeURIComponent, escape, eval, expect, exports, fetch, global, globalThis, isFinite, isNaN, jest, module, parseFloat, parseInt, performance, process, queueMicrotask, require, setImmediate, setInterval, setTimeout, structuredClone, undefined, unes...
The students can get an understanding of the types of questions to expect through official JEST 2025 exam mock tests as they broadly represent question samples. Also Read:JEST Sample Papers JEST 2025 Exam Centres JEST 2025 exam centres have been released by the conducting body for the exam SER...
、UI等内容的测试,快照保存上次运行的结果存储在 __snapshots__ 下,如果两次执行结果不一致则不通过,需要检查后更新快照,按 u 更新全部快照,按 i 进入交互式单独更新。...(generateConfig2()).toMatchInlineSnapshot({ time: expect.any(Date) }); }); 执行后快照保存在用例文件中 test("测试...,node ...
it('will check the matchers and pass', () => { const user = { createdAt: new Date(), id: Math.floor(Math.random() * 20), name: 'LeBron James', }; expect(user).toMatchSnapshot({ createdAt: expect.any(Date), id: expect.any(Number), }); }); // Snapshot exports[`will ...