Skip to content

Commit

Permalink
test(codegen/parsers-commons): add broken test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Doubovetzky committed Oct 29, 2022
1 parent 3dc7b37 commit 2f16116
Showing 1 changed file with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ describe('assertGenericTypeAnnotationHasExactlyOneTypeParameter', () => {
);
});

it("throws an IncorrectlyParameterizedGenericParserError if typeParameters don't have 1 exactly parameter", () => {
it("throws an IncorrectlyParameterizedGenericParserError if typeParameters don't have 1 exactly parameter for Flow", () => {
const language: ParserType = 'Flow';
const typeAnnotationWithTwoParams = {
typeParameters: {
params: [1, 2],
Expand All @@ -181,7 +182,7 @@ describe('assertGenericTypeAnnotationHasExactlyOneTypeParameter', () => {
assertGenericTypeAnnotationHasExactlyOneTypeParameter(
moduleName,
typeAnnotationWithTwoParams,
'Flow',
language,
),
).toThrowErrorMatchingInlineSnapshot(
`"Module testModuleName: Generic 'typeAnnotationName' must have exactly one type parameter."`,
Expand All @@ -200,7 +201,48 @@ describe('assertGenericTypeAnnotationHasExactlyOneTypeParameter', () => {
assertGenericTypeAnnotationHasExactlyOneTypeParameter(
moduleName,
typeAnnotationWithNoParams,
'Flow',
language,
),
).toThrowErrorMatchingInlineSnapshot(
`"Module testModuleName: Generic 'typeAnnotationName' must have exactly one type parameter."`,
);
});

it("throws an IncorrectlyParameterizedGenericParserError if typeParameters don't have 1 exactly parameter for TS", () => {
const language: ParserType = 'TypeScript';
const typeAnnotationWithTwoParams = {
typeParameters: {
params: [1, 2],
type: 'TSTypeParameterInstantiation',
},
typeName: {
name: 'typeAnnotationName',
},
};
expect(() =>
assertGenericTypeAnnotationHasExactlyOneTypeParameter(
moduleName,
typeAnnotationWithTwoParams,
language,
),
).toThrowErrorMatchingInlineSnapshot(
`"Module testModuleName: Generic 'typeAnnotationName' must have exactly one type parameter."`,
);

const typeAnnotationWithNoParams = {
typeParameters: {
params: [],
type: 'TSTypeParameterInstantiation',
},
typeName: {
name: 'typeAnnotationName',
},
};
expect(() =>
assertGenericTypeAnnotationHasExactlyOneTypeParameter(
moduleName,
typeAnnotationWithNoParams,
language,
),
).toThrowErrorMatchingInlineSnapshot(
`"Module testModuleName: Generic 'typeAnnotationName' must have exactly one type parameter."`,
Expand Down

0 comments on commit 2f16116

Please sign in to comment.