Skip to content
This repository was archived by the owner on Apr 18, 2023. It is now read-only.
This repository was archived by the owner on Apr 18, 2023. It is now read-only.

wrapper.unmount not calling useEffect cleanup #12

@Johannes-Andersen

Description

@Johannes-Andersen

Hey, hope all is well.

Hopefully, this is the right place, but feel free to let me know if I am doing something stupid.

So I have attempted to upgrade to react 17, but found all my tests related to useEffect cleanup's are not passing anymore. It would seem like they are triggered.

Example below is an example where the console log never gets called, and the toHaveBeenCalledTimes is 0.
Screenshot 2021-02-25 at 18 59 31

Here is the test:

  it('should call ruleModel.resetState when unmounted', () => {
    const resetState = jest.fn()
    const ruleModel = {
      resetState: action(resetState),
    }
    const wrapper = renderWrapper({ ruleModel })
    wrapper.unmount()
    expect(resetState).toHaveBeenCalledTimes(1)
  })

And here is the hook:

  useEffect(() => {
    if (ruleId) getRule(ruleId)
    return () => {
      console.log('hello')
      resetState()
    }
  }, [ruleId, getRule, resetState])

Here is a snippet of the renderWrapper function:

import { mount, ReactWrapper } from 'enzyme'

const renderWrapper = ({[...]}: any): ReactWrapper => {

  const store = createStore({[...]})

  return mount(
    <StoreProvider store={store}>
      <NewRuleConditionsPage
        onDiscard={onDiscard}
        ruleId={ruleId}
      />
    </StoreProvider>
  )
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions