swpp201901-team06 / swpp-project

1 stars 2 forks source link

Simulating SideBar click logout button #71

Open lionminhu opened 5 years ago

lionminhu commented 5 years ago

To test this portion of the SideBar molecule: https://github.com/swpp201901-team06/swpp-project/blob/0f97e090c015914bb6e853ed80b10fdc39673cfd/FD_frontend/src/components/molecules/SideBar/index.js#L6-L9

I've created a test as the following:

  it('clear localStorage on logout', () => {
    // global.localStorage = {
    //   clear: jest.fn(),
    // }
    // global.location = {
    //   href: 'some_href',
    // }
    const props = {
      statefunction: {
        SignInPage: {
          nickname: 'test_nickname',
          isLoggedIn: true,
        },
      },
      onClickMyArchive,
    }
    const wrapper = wrap(props)
    wrapper.find('SideBarButton').at(1).simulate('click')
    // expect(global.localStorage.clear).toHaveBeenCalled()
  })

The following error message shows up on npm test:

FAIL  src/components/molecules/SideBar/index.test.js
  ● SideBar molecule test › clear localStorage on logout

    TypeError: Could not parse "/" as a URL

      at LocationImpl.set href [as href] (node_modules/jsdom/lib/jsdom/living/window/Location-impl.js:46:13)
      at Location.set [as href] (node_modules/jsdom/lib/jsdom/living/generated/Location.js:58:21)
      at onClickLogout (src/components/molecules/SideBar/index.js:8:26)
      at node_modules/enzyme-adapter-react-15/build/ReactFifteenAdapter.js:329:29
      at ReactDefaultBatchingStrategyTransaction.perform (node_modules/react-test-renderer/lib/shallow/Transaction.js:140:20)
      at Object.batchedUpdates (node_modules/react-test-renderer/lib/shallow/ReactDefaultBatchingStrategy.js:62:26)
      at Object.batchedUpdates (node_modules/react-test-renderer/lib/shallow/ReactUpdates.js:97:27)
      at ReactShallowRenderer.unstable_batchedUpdates (node_modules/react-test-renderer/lib/shallow/ReactShallowRenderer.js:130:25)
      at node_modules/enzyme-adapter-react-15/build/ReactFifteenAdapter.js:328:28
      at withSetStateAllowed (node_modules/enzyme-adapter-utils/build/Utils.js:153:16)

@theNocturni Could you check the implementation here? Or rather, were you planning to use the onLogout, which was provided in the props for SideBar?