-
Notifications
You must be signed in to change notification settings - Fork 232
Closed
Labels
questionFurther information is requestedFurther information is requested
Description
I have a simple custom hook like so:
import { useState } from 'react';
export default function useOpenClose(initial = false) {
const [isOpen, setOpen] = useState(initial);
const open = () => { setOpen(true); }
const close = () => { setOpen(false); }
return [isOpen, { open, close }];
}
I have a test that's somewhat passing. When I have a test that updates state, it doesn't seem to work.
The test in question:
import { renderHook, act } from '@testing-library/react-hooks';
import useOpenClose from './useOpenClose';
describe('useOpenClose', () => {
const { result: { current } } = renderHook(() => useOpenClose());
const [isOpen, { open, close }] = current;
test('Should have initial value of false', () => {
expect(isOpen).toBe(false);
});
test('Should update value to true', () => {
act(() => open())
console.log(isOpen)
})
});
Test 1 passes, but when I console.log(isOpen)
for test 2, isOpen
remains false.
Does it have anything to do with the array destructuring? Is it immutable? Or is it the way I'm using act()
?
Sivanesh-S
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested