Skip to content

Commit

Permalink
Add a few more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Jul 13, 2020
1 parent d725a6b commit e85dcbe
Showing 1 changed file with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6995,6 +6995,18 @@ const testsTypescript = {
}
`,
},
{
code: normalizeIndent`
function App() {
const foo = {x: 1};
React.useEffect(() => {
const bar = {x: 2};
const baz = bar as typeof foo;
console.log(baz);
}, []);
}
`,
},
],
invalid: [
{
Expand Down Expand Up @@ -7028,6 +7040,40 @@ const testsTypescript = {
},
],
},
{
code: normalizeIndent`
function App() {
const foo = {x: 1};
const bar = {x: 2};
useEffect(() => {
const baz = bar as typeof foo;
console.log(baz);
}, []);
}
`,
errors: [
{
message:
"React Hook useEffect has a missing dependency: 'bar'. " +
'Either include it or remove the dependency array.',
suggestions: [
{
desc: 'Update the dependencies array to be: [bar]',
output: normalizeIndent`
function App() {
const foo = {x: 1};
const bar = {x: 2};
useEffect(() => {
const baz = bar as typeof foo;
console.log(baz);
}, [bar]);
}
`,
},
],
},
],
},
{
code: normalizeIndent`
function MyComponent() {
Expand Down Expand Up @@ -7233,7 +7279,7 @@ const testsTypescript = {
code: normalizeIndent`
function MyComponent() {
const [state, setState] = React.useState<number>(0);
useEffect(() => {
const someNumber: typeof state = 2;
setState(prevState => prevState + someNumber + state);
Expand All @@ -7253,7 +7299,7 @@ const testsTypescript = {
output: normalizeIndent`
function MyComponent() {
const [state, setState] = React.useState<number>(0);
useEffect(() => {
const someNumber: typeof state = 2;
setState(prevState => prevState + someNumber + state);
Expand All @@ -7269,7 +7315,7 @@ const testsTypescript = {
code: normalizeIndent`
function MyComponent() {
const [state, setState] = React.useState<number>(0);
useMemo(() => {
const someNumber: typeof state = 2;
console.log(someNumber);
Expand All @@ -7287,7 +7333,7 @@ const testsTypescript = {
output: normalizeIndent`
function MyComponent() {
const [state, setState] = React.useState<number>(0);
useMemo(() => {
const someNumber: typeof state = 2;
console.log(someNumber);
Expand Down

0 comments on commit e85dcbe

Please sign in to comment.