-
Notifications
You must be signed in to change notification settings - Fork 15
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
5 changed files
with
41 additions
and
10 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
27 changes: 27 additions & 0 deletions
27
assets/js/common/DismissableToast/DismissableToast.test.jsx
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,27 @@ | ||
import React from 'react'; | ||
import { toast } from 'react-hot-toast'; | ||
import { screen, render } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import DismissableToast from '.'; | ||
|
||
describe('DismissableToast component', () => { | ||
afterEach(() => { | ||
// restore the spy created with spyOn | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
it('renders the text and forward the onclick event with the provided prop id', async () => { | ||
const spy = jest.spyOn(toast, 'dismiss'); | ||
const toastID = 'toast-1'; | ||
const user = userEvent.setup(); | ||
|
||
render(<DismissableToast text="test" id={toastID} />); | ||
|
||
expect(screen.getByText('test')).toBeVisible(); | ||
await user.click(screen.getByText('Close')); | ||
|
||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
}); |
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