forked from jestjs/jest
/
asynchronous.test.js
33 lines (29 loc) 路 1.17 KB
/
asynchronous.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const {toMatchInlineSnapshot} = require('jest-snapshot');
expect.extend({
async toMatchObservationInlineSnapshot(fn, ...args) {
this.error = new Error();
// This specific behavior can be implemented without a custom matcher.
// In a real example one might want to observe some global value that `fn()` is affecting.
// The difference between before and after `fn()` might then be persisted as a snapshot.
const result = await fn();
return toMatchInlineSnapshot.call(this, result, ...args);
},
});
test('new async, inline snapshots', async () => {
await expect(async () => 'result #1').toMatchObservationInlineSnapshot();
await expect(async () => 'result #2').toMatchObservationInlineSnapshot();
});
test('mismatching async, inline snapshots', async () => {
await expect(async () => 'result #1').toMatchObservationInlineSnapshot(
`"result #?"`,
);
await expect(async () => 'result #2').toMatchObservationInlineSnapshot(
`"result #?"`,
);
});