-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor tests to pull out the mountMockedProvider functions
- Create a separate file to contain the mountMockedProvider function which is re-used in a number of tests, making it generic Co-authored-by: Riccardo Giomi <contact@riccardogiomi.com>
- Loading branch information
Showing
6 changed files
with
47 additions
and
152 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 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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react' | ||
import { mount } from 'enzyme' | ||
import { MockedProvider } from '@apollo/react-testing' | ||
import { act } from 'react-dom/test-utils' | ||
import { MemoryRouter as Router } from 'react-router-dom' | ||
|
||
export async function mountMockedProvider(result, query, currentComponent, variables) { | ||
const request = variables ? { query, variables } : { query } | ||
const mocks = [ | ||
{ | ||
request, | ||
result | ||
} | ||
] | ||
|
||
jest.useFakeTimers() | ||
const component = mount( | ||
<MockedProvider | ||
mocks={mocks} | ||
addTypename={false} | ||
> | ||
<Router> | ||
{ currentComponent } | ||
</Router> | ||
</MockedProvider>) | ||
act(() => { | ||
jest.runAllTimers() | ||
}) | ||
component.update() | ||
return component | ||
} |