Skip to content

Commit 86bba6b

Browse files
Louis KuczykowskiLouis Kuczykowski
authored andcommitted
Combined LK/tc6 and LK/tc7 so test cases are on one branch for dev merge
2 parents 02bfdc5 + fc7e728 commit 86bba6b

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

src/test/suite/parser.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ describe('Parser Test Suite', () => {
6464
})
6565
})
6666

67+
// TEST 7: SYNTAX ERROR IN APP FILE CAUSES PARSER ERROR
68+
describe('Parser should not work for components with syntax errors in the code', () => {
69+
beforeEach(() => {
70+
file = path.join(__dirname, '../../../../src/test/test_cases/tc_7/index.js');
71+
parser = new Parser(file);
72+
tree = parser.parse();
73+
});
74+
test("Parser stops parsing when there is a syntax error in a component", () => {
75+
expect(tree.children[0].name).toBe('App');
76+
expect(tree.children[0].error).not.toBeUndefined;
77+
expect((tree.children[0].children).length).toBe(0);
78+
});
79+
})
80+
6781
// these are the 14 tests we need to test for
6882

6983
// TEST 1: NESTED CHILDREN
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React, { Component } from 'react';
2+
import ChildApp from './ChildApp';
3+
4+
export const App = () => {
5+
this should not work when given to the parser
6+
return (
7+
<div>
8+
<p>Syntax Error</p>
9+
<ChildApp />
10+
</div>
11+
)
12+
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// this component will not show up in the children of App due to App's syntax error
2+
import React, { Component } from 'react';
3+
4+
export const ChildApp = () => {
5+
return (
6+
<div>
7+
<p>Child of App with Syntax Error</p>
8+
</div>
9+
)
10+
11+
}

src/test/test_cases/tc_7/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//! TEST 7: SYNTAX ERROR IN APP FILE CAUSES PARSER ERROR
2+
3+
import React from 'react';
4+
import { createRoot } from 'react-dom/client';
5+
import App from './components/App.jsx';
6+
7+
const root = createRoot(document.getElementById('root'));
8+
root.render(<App />);

0 commit comments

Comments
 (0)