Skip to content

Commit

Permalink
Add another failed test case
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed May 10, 2023
1 parent 182df1c commit 2610460
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/forgetti/test/__snapshots__/hooks.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@ function Example(props) {
}"
`;
exports[`hooks > should correct transform derived hooks call 1`] = `
"import { useMemo as _useMemo } from \\"react\\";
import { $$cache as _$$cache } from \\"forgetti/runtime\\";
import { $$equals as _$$equals } from \\"forgetti/runtime\\";
import { useA, useB, useC } from 'whatever';
function Example(props) {
let _c = _$$cache(_useMemo, 3),
a = null,
_eq = _$$equals(_c, 0, useA()),
_v = _eq ? _c[0] : _c[0] = useA(),
_eq2 = _$$equals(_c, 1, useC()),
_v2 = _eq2 ? _c[1] : _c[1] = useC(),
_eq3 = _eq && _eq2,
_v3 = _eq3 ? _c[2] : _c[2] = {
[_v]: useB(),
..._v2
};
return _v3;
}"
`;
exports[`hooks > should correct transform nested hooks call (issue #14) 1`] = `
"import { useDeferredValue } from 'react';
import { useAtomValue } from 'jotai';
Expand Down
11 changes: 11 additions & 0 deletions packages/forgetti/test/hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ function Example(props) {
...useJ()
);
}
`;
expect(await compile(code)).toMatchSnapshot();
});
it('should correct transform derived hooks call', async () => {
const code = `
import { useA, useB, useC } from 'whatever'
function Example(props) {
let a = null;
return { [useA()]: useB(), ...useC(), [\`testA\${useH()}testB\`]: useI() === useJ() }
}
`;
expect(await compile(code)).toMatchSnapshot();
});
Expand Down

0 comments on commit 2610460

Please sign in to comment.