Skip to content

Commit

Permalink
test: change toMatchSnapshot to toMatchInlineSnapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Dec 20, 2021
1 parent cdafca7 commit f7949b4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 45 deletions.
28 changes: 0 additions & 28 deletions packages/parser/tests/lib/__snapshots__/tsx.ts.snap

This file was deleted.

57 changes: 40 additions & 17 deletions packages/parser/tests/lib/tsx.ts
@@ -1,21 +1,34 @@
import { parseForESLint } from '../../src/parser';
import { serializer } from '../tools/ts-error-serializer';
import type { ParserOptions } from '@typescript-eslint/types';

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

expect.addSnapshotSerializer(serializer);

function parseWithError(code: string, options?: ParserOptions | null): unknown {
try {
return parseForESLint(code, options);
} catch (e) {
return e;
}
}

describe('TSX', () => {
describe("if the filename ends with '.tsx', enable jsx option automatically.", () => {
it('filePath was not provided', () => {
const code = 'const element = <T/>';
try {
parseForESLint(code);
} catch (e) {
expect(e).toMatchSnapshot();
}

expect(parseWithError(code)).toMatchInlineSnapshot(`
TSError {
"column": 18,
"index": 18,
"lineNumber": 1,
"message": "'>' expected.",
}
`);
});

it("filePath was not provided and 'jsx:true' option", () => {
Expand All @@ -31,28 +44,38 @@ describe('TSX', () => {

it('test.ts', () => {
const code = 'const element = <T/>';
try {
parseForESLint(code, {
expect(
parseWithError(code, {
filePath: 'test.ts',
});
} catch (e) {
expect(e).toMatchSnapshot();
}
}),
).toMatchInlineSnapshot(`
TSError {
"column": 18,
"index": 18,
"lineNumber": 1,
"message": "'>' expected.",
}
`);
});

it("test.ts with 'jsx:true' option", () => {
const code = 'const element = <T/>';

try {
parseForESLint(code, {
expect(
parseWithError(code, {
filePath: 'test.ts',
ecmaFeatures: {
jsx: true,
},
});
} catch (e) {
expect(e).toMatchSnapshot();
}
}),
).toMatchInlineSnapshot(`
TSError {
"column": 18,
"index": 18,
"lineNumber": 1,
"message": "'>' expected.",
}
`);
});

it('test.tsx', () => {
Expand Down

0 comments on commit f7949b4

Please sign in to comment.