Skip to content

Commit 7fd9995

Browse files
authored
Merge pull request #119 from open-source-labs/ast-implementation-testing
added test cases sample for astParser.js
2 parents 6828d73 + 774c1ba commit 7fd9995

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

package/__tests__/astParser.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Test 1: Should take in a function definition with 1 hook and return an object with the getter/setter
2+
// EXAMPLE INPUT FOR TEST
3+
/**
4+
* function UseStateHookTest() {
5+
* const [testCount, setTestCount] = useState(0);
6+
* return (
7+
* <div>
8+
* <p>You clicked this {useStateCount} times</p>
9+
* <button onClick={() => setTestCount(testCount + 1)}>+1</button>
10+
* <button onClick={() => setTestCount(testCount - 1)}>-1</button>
11+
* <hr />
12+
* </div>
13+
* );
14+
* }
15+
*/
16+
17+
// EXPECTED RESULT of astParser(input)
18+
/**
19+
* {
20+
* _useState: "testCount",
21+
* _useState2: "setTestCount"
22+
* }
23+
*/
24+
25+
// TEST 2: Should take in multiple function definitions with hooks and return an object with all 4 properties
26+
// TEST 3: Should ignore any non-hook definitions
27+
// Test 4: Should return an empty object if no hooks found
28+
// Test 5: Should throw an error if input is invalid javascript

0 commit comments

Comments
 (0)