-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TestSetupProvider for mocking SetupProvider more effectively
- Loading branch information
Showing
7 changed files
with
77 additions
and
93 deletions.
There are no files selected for viewing
24 changes: 11 additions & 13 deletions
24
src/components/Layouts/Primary/LogoLink/LogoLink.test.tsx
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,25 +1,23 @@ | ||
import { render } from '@testing-library/react'; | ||
import { useSetupContext } from 'src/components/Setup/SetupProvider'; | ||
import { TestSetupProvider } from 'src/components/Setup/SetupProvider'; | ||
import { LogoLink } from './LogoLink'; | ||
|
||
jest.mock('src/components/Setup/SetupProvider'); | ||
|
||
describe('LogoLink', () => { | ||
it('renders a link when not on the setup tour', () => { | ||
(useSetupContext as jest.MockedFn<typeof useSetupContext>).mockReturnValue({ | ||
onSetupTour: false, | ||
}); | ||
|
||
const { getByRole } = render(<LogoLink />); | ||
const { getByRole } = render( | ||
<TestSetupProvider> | ||
<LogoLink /> | ||
</TestSetupProvider>, | ||
); | ||
expect(getByRole('link')).toBeInTheDocument(); | ||
}); | ||
|
||
it('does not render a link when on the setup tour', () => { | ||
(useSetupContext as jest.MockedFn<typeof useSetupContext>).mockReturnValue({ | ||
onSetupTour: true, | ||
}); | ||
|
||
const { queryByRole } = render(<LogoLink />); | ||
const { queryByRole } = render( | ||
<TestSetupProvider onSetupTour> | ||
<LogoLink /> | ||
</TestSetupProvider>, | ||
); | ||
expect(queryByRole('link')).not.toBeInTheDocument(); | ||
}); | ||
}); |
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