Skip to content

Commit e79f432

Browse files
committed
Add e2e test for documented implementation
1 parent 016a921 commit e79f432

4 files changed

Lines changed: 154 additions & 0 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`works with custom inline snapshot matchers 1`] = `
4+
FAIL __tests__/asynchronous.test.js
5+
✕ new async, inline snapshots
6+
✕ mismatching async, inline snapshots
7+
8+
● new async, inline snapshots
9+
10+
expect(received).toMatchInlineSnapshot()
11+
12+
Snapshot name: \`new async, inline snapshots 1\`
13+
14+
New snapshot was not written. The update flag must be explicitly passed to write a new snapshot.
15+
16+
This is likely because this test is run in a continuous integration (CI) environment in which snapshots are not written by default.
17+
18+
Received: "result #1"
19+
20+
17 |
21+
18 | test('new async, inline snapshots', async () => {
22+
> 19 | await expect(async () => 'result #1').toMatchObservationInlineSnapshot();
23+
| ^
24+
20 | await expect(async () => 'result #2').toMatchObservationInlineSnapshot();
25+
21 | });
26+
22 |
27+
28+
at Object.toMatchObservationInlineSnapshot (__tests__/asynchronous.test.js:19:41)
29+
30+
● new async, inline snapshots
31+
32+
expect(received).toMatchInlineSnapshot()
33+
34+
Snapshot name: \`new async, inline snapshots 2\`
35+
36+
New snapshot was not written. The update flag must be explicitly passed to write a new snapshot.
37+
38+
This is likely because this test is run in a continuous integration (CI) environment in which snapshots are not written by default.
39+
40+
Received: "result #2"
41+
42+
18 | test('new async, inline snapshots', async () => {
43+
19 | await expect(async () => 'result #1').toMatchObservationInlineSnapshot();
44+
> 20 | await expect(async () => 'result #2').toMatchObservationInlineSnapshot();
45+
| ^
46+
21 | });
47+
22 |
48+
23 | test('mismatching async, inline snapshots', async () => {
49+
50+
at Object.toMatchObservationInlineSnapshot (__tests__/asynchronous.test.js:20:41)
51+
52+
mismatching async, inline snapshots
53+
54+
expect(received).toMatchInlineSnapshot(snapshot)
55+
56+
Snapshot name: \`mismatching async, inline snapshots 1\`
57+
58+
Snapshot: "result #?"
59+
Received: "result #1"
60+
61+
22 |
62+
23 | test('mismatching async, inline snapshots', async () => {
63+
> 24 | await expect(async () => 'result #1').toMatchObservationInlineSnapshot(
64+
| ^
65+
25 | \`"result #?"\`,
66+
26 | );
67+
27 | await expect(async () => 'result #1').toMatchObservationInlineSnapshot(
68+
69+
at Object.toMatchObservationInlineSnapshot (__tests__/asynchronous.test.js:24:41)
70+
71+
● mismatching async, inline snapshots
72+
73+
expect(received).toMatchInlineSnapshot(snapshot)
74+
75+
Snapshot name: \`mismatching async, inline snapshots 2\`
76+
77+
Snapshot: "result #?"
78+
Received: "result #1"
79+
80+
25 | \`"result #?"\`,
81+
26 | );
82+
> 27 | await expect(async () => 'result #1').toMatchObservationInlineSnapshot(
83+
| ^
84+
28 | \`"result #?"\`,
85+
29 | );
86+
30 | });
87+
88+
at Object.toMatchObservationInlineSnapshot (__tests__/asynchronous.test.js:27:41)
89+
90+
› 4 snapshots failed.
91+
Snapshot Summary
92+
› 4 snapshots failed from 1 test suite. Inspect your code changes or re-run jest with \`-u\` to update them.
93+
`;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import {wrap} from 'jest-snapshot-serializer-raw';
9+
import {extractSummary} from '../Utils';
10+
import runJest from '../runJest';
11+
12+
test('works with custom inline snapshot matchers', () => {
13+
const {stderr} = runJest('custom-inline-snapshot-matchers', [
14+
'--ci',
15+
'asynchronous.test.js',
16+
]);
17+
18+
let {rest} = extractSummary(stderr);
19+
20+
rest = rest
21+
.split('\n')
22+
.filter(line => line.indexOf('at Error (native)') < 0)
23+
.join('\n');
24+
25+
expect(wrap(rest)).toMatchSnapshot();
26+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
const {toMatchInlineSnapshot} = require('jest-snapshot');
8+
9+
expect.extend({
10+
async toMatchObservationInlineSnapshot(fn, ...args) {
11+
this.error = new Error();
12+
const result = await fn();
13+
14+
return toMatchInlineSnapshot.call(this, result, ...args);
15+
},
16+
});
17+
18+
test('new async, inline snapshots', async () => {
19+
await expect(async () => 'result #1').toMatchObservationInlineSnapshot();
20+
await expect(async () => 'result #2').toMatchObservationInlineSnapshot();
21+
});
22+
23+
test('mismatching async, inline snapshots', async () => {
24+
await expect(async () => 'result #1').toMatchObservationInlineSnapshot(
25+
`"result #?"`,
26+
);
27+
await expect(async () => 'result #1').toMatchObservationInlineSnapshot(
28+
`"result #?"`,
29+
);
30+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"jest": {
3+
"testEnvironment": "node"
4+
}
5+
}

0 commit comments

Comments
 (0)