Skip to content

Commit 06fc66a

Browse files
author
Christoph Bühler
committed
test: adding tests for react files
1 parent b87cc20 commit 06fc66a

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

test/TypescriptParser.spec.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('TypescriptParser', () => {
3232

3333
it('should parse a source code string correctly', async () => {
3434
const parsed = await parser.parseSource(`import {foo} from 'bar'; class Foobar {}; const bar = new Foobar();`);
35-
35+
3636
expect(parsed).toMatchSnapshot();
3737
});
3838

@@ -544,4 +544,22 @@ describe('TypescriptParser', () => {
544544

545545
});
546546

547+
describe('TSX Usage parsing', () => {
548+
const file = getWorkspaceFile('typescript-parser/usagesOnly.tsx');
549+
let parsed: Resource;
550+
551+
beforeEach(async () => {
552+
parsed = await parser.parseFile(file, rootPath);
553+
});
554+
555+
it('should parse a tsx element usage', () => {
556+
const usages = parsed.usages;
557+
558+
expect(usages).toContain('myComponent');
559+
expect(usages).toContain('div');
560+
expect(usages).toContain('complexComp');
561+
expect(usages).toContain('SingleComp');
562+
});
563+
});
564+
547565
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { myComponent } from './myReactTemplate';
2+
3+
export default function foobar() {
4+
return (
5+
<myComponent></myComponent>
6+
);
7+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default function foobar() {
2+
return (
3+
<myComponent>
4+
<div>
5+
<complexComp>
6+
<SingleComp />
7+
</complexComp>
8+
</div>
9+
</myComponent>
10+
);
11+
}

0 commit comments

Comments
 (0)