-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
13 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,18 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import * as router from 'react-router-dom'; | ||
import LogOut from '../../../../../client/src/components/signin/logout'; | ||
import RESTcall from '../../../../../client/src/crud'; | ||
|
||
const mockdispatch = jest.fn(); | ||
// Mock RESTcall | ||
jest.mock('../../../../../client/src/crud'); | ||
// Mock redux hooks | ||
jest.mock('react-redux', () => ({ | ||
...jest.requireActual('react-redux'), // use actual for all non-hook parts | ||
useDispatch: jest.fn(() => mockdispatch), | ||
})); | ||
|
||
// Mock router hooks | ||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), // use actual for all non-hook parts | ||
useHistory: jest.fn(), | ||
})); | ||
const windowSpy = jest.spyOn(window, 'location', 'get'); | ||
const mockedAssign: jest.Mock = jest.fn(); | ||
windowSpy.mockReturnValue({ | ||
...window.location, | ||
assign: mockedAssign, | ||
}); | ||
|
||
xtest('will logout a user', async () => { | ||
const replace = jest.fn(); | ||
const hist = router.useHistory(); | ||
jest | ||
.spyOn(router, 'useHistory') | ||
.mockImplementation(() => ({ ...hist, replace })); | ||
test('will logout a user', () => { | ||
shallow(<LogOut />); | ||
await Promise.resolve(); | ||
expect(RESTcall).toHaveBeenCalledWith({ address: '/auth/logout' }); | ||
expect(mockdispatch).toHaveBeenCalled(); | ||
expect(replace).toHaveBeenCalledWith('/'); | ||
expect(mockedAssign).toHaveBeenCalledWith('/auth/logout'); | ||
}); |