Skip to content

Commit 3437e41

Browse files
committed
tests: add for scope based and multiple components
1 parent bacb536 commit 3437e41

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

test/snapshots/test.ts.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,23 @@ Generated by [AVA](https://avajs.dev).
5959
onClick: onPress␊
6060
}, "Press"));␊
6161
}`
62+
63+
## Check Arrow Function Scope
64+
65+
> Snapshot 1
66+
67+
`import * as React from "react";␊
68+
let $b = 2;␊
69+
70+
const Component = () => {␊
71+
const [a, setA] = React.useState(1);␊
72+
73+
const onPress = () => {␊
74+
setA(a + 1);␊
75+
$b = 3;␊
76+
};␊
77+
78+
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("p", null, a), /*#__PURE__*/React.createElement("button", {␊
79+
onClick: onPress␊
80+
}, "Press"));␊
81+
};`

test/snapshots/test.ts.snap

49 Bytes
Binary file not shown.

test/test.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,79 @@ test('Check Functional Scope', (t) => {
5959
}
6060
t.snapshot(result.code)
6161
})
62+
63+
test('Check Arrow Function Scope', (t) => {
64+
const code = `
65+
import * as React from "react";
66+
67+
let $b = 2;
68+
69+
const Component = () => {
70+
let $a = 1;
71+
72+
const onPress = () => {
73+
$a += 1;
74+
$b = 3;
75+
};
76+
77+
return (
78+
<div>
79+
<p>{$a}</p>
80+
<button onClick={onPress}>Press</button>
81+
</div>
82+
);
83+
};
84+
`
85+
86+
const result = compile(code)
87+
if (!result) {
88+
return t.fail()
89+
}
90+
t.snapshot(result.code)
91+
})
92+
93+
test('Multi Component Scope', (t) => {
94+
const code = `
95+
import * as React from "react";
96+
97+
let $b = 2;
98+
99+
const Component = () => {
100+
let $a = 1;
101+
102+
const onPress = () => {
103+
$a += 1;
104+
$b = 3;
105+
};
106+
107+
return (
108+
<div>
109+
<p>{$a}</p>
110+
<button onClick={onPress}>Press</button>
111+
</div>
112+
);
113+
};
114+
115+
const ComponentTwo = () => {
116+
let $a = 3;
117+
118+
const onPress = () => {
119+
$a = 5;
120+
$b = 3;
121+
};
122+
123+
return (
124+
<div>
125+
<p>{$a}</p>
126+
<button onClick={onPress}>Press</button>
127+
</div>
128+
);
129+
};
130+
`
131+
132+
const result = compile(code)
133+
if (!result) {
134+
return t.fail()
135+
}
136+
t.snapshot(result.code)
137+
})

0 commit comments

Comments
 (0)