Skip to content

Commit 0029258

Browse files
committed
add more tests
1 parent b382d76 commit 0029258

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
export default function Button() {
5+
// if a function does not return JSX, we throw
6+
return { type: 'button' };
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"include": ["./**/*.tsx"]
4+
}

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export function documentComponents(
3737
const moduleSymbol = checker.getSymbolAtLocation(sourceFile);
3838
const name = componentNameFromPath(sourceFile.fileName);
3939

40+
// istanbul ignore next
4041
if (!moduleSymbol) {
4142
throw new Error(`Unable to resolve module: ${sourceFile.fileName}`);
4243
}

test/components/errors.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ test('should throw error when multiple components exported from the main file',
1414
expect(() => buildProject('ambiguous-exports')).toThrow('Missing default export for Component');
1515
});
1616

17+
test('should throw error if default export is not a react component', () => {
18+
expect(() => buildProject('error-not-a-component')).toThrow('Unknown default export type () => { type: string; }');
19+
});
20+
1721
test('should throw error if event handler has an invalid type', () => {
1822
expect(() => buildProject('unknown-event-handler')).toThrow('Unknown event handler type: string');
1923
});

0 commit comments

Comments
 (0)