jest
jest copied to clipboard
"Cannot access 'aVariable' before initialization" with React
On a React project, I switched ts-jest
+ babel-jest
to @swc/jest
Few tests are now failing with the same type of error : Cannot access 'aVariable' before initialization
which always happen in a specific situation.
The error is thrown when the variable is defined further in the component, but used before by a React function :
function AComponent() {
const aFunction = () => { //Case 1
return aVariable;
};
const [selected, setSelected] = useState(() => { //Case 2
return aVariable;
});
const otherTest = useMemo(() => aVariable, []); //Case 3
const aVariable = 'Ceci est un test';
}
- Case 1 work
- Case 2 fail
- Case 3 fail
Any update around this?
@kdy1
I have time to work on it. Any hint about this issue and where should I start?
@erfanium You can add tests to https://github.com/swc-project/swc/tree/ebebd608750bf63d6f715350835a1a5349efdb68/crates/swc/tests/fixture/jest and do UPDATE=1 cargo test
to investigate
any update on fixing this issue?
bump