Skip to content

Commit

Permalink
Add test cases for jestjs#6744
Browse files Browse the repository at this point in the history
  • Loading branch information
azz committed Jul 28, 2018
1 parent 0f525c5 commit 91d5ca5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
11 changes: 11 additions & 0 deletions e2e/__tests__/__snapshots__/to_match_inline_snapshot.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,14 @@ exports[`supports async tests 1`] = `
});
"
`;
exports[`writes snapshots with non-literals in expect(...) 1`] = `
"it('works with inline snapshots', () => {
expect({a: 1}).toMatchInlineSnapshot(\`
Object {
\\"a\\": 1,
}
\`);
});
"
`;
16 changes: 16 additions & 0 deletions e2e/__tests__/to_match_inline_snapshot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,19 @@ test('supports async tests', () => {
expect(status).toBe(0);
expect(fileAfter).toMatchSnapshot();
});

test('writes snapshots with non-literals in expect(...)', () => {
const filename = 'async.test.js';
const test = `
it('works with inline snapshots', () => {
expect({a: 1}).toMatchInlineSnapshot();
});
`;

writeFiles(TESTS_DIR, {[filename]: test});
const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]);
const fileAfter = readFile(filename);
expect(stderr).toMatch('1 snapshot written from 1 test suite.');
expect(status).toBe(0);
expect(fileAfter).toMatchSnapshot();
});
27 changes: 27 additions & 0 deletions packages/jest-snapshot/src/__tests__/inline_snapshots.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,30 @@ test('saveInlineSnapshots() uses escaped backticks', () => {
'expect("`").toMatchInlineSnapshot(`\\``);\n',
);
});

test('saveInlineSnapshots() works with non-literals in expect call', () => {
const filename = path.join(__dirname, 'my.test.js');
fs.readFileSync = (jest.fn(
() => `expect({a: 'a'}).toMatchInlineSnapshot();\n`,
): any);
prettier.resolveConfig.sync.mockReturnValue({
bracketSpacing: false,
singleQuote: true,
});

saveInlineSnapshots(
[
{
frame: {column: 18, file: filename, line: 1},
snapshot: `{a: 'a'}`,
},
],
prettier,
babelTraverse,
);

expect(fs.writeFileSync).toHaveBeenCalledWith(
filename,
"expect({a: 'a'}).toMatchInlineSnapshot(`{a: 'a'}`);\n",
);
});

0 comments on commit 91d5ca5

Please sign in to comment.