I am trying to write a unit test using jest and react testing library. I want to test a function call inside the useEffect hook, but my test is not working. What do I need to do to pass the test successfully?
useEffect(() => {
getActiveFilters(filterValue);
// eslint-disable-next-line
}, [filterValue, dictionaries]);
Here my test
it('should call the [getActiveFilters] function', async () => {
const getActiveFilters = jest.fn();
await waitFor(() => expect(getActiveFilters).toHaveBeenCalled());
});
jest.fn()
... there's no connection to the component you want to test. Test the results of this function (eg. some changes in the rendered content), not the implementation of some function.. – Deterge