forked from binary-com/deriv-app
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WALL] farhan/chore: 🐣 unit test for WalletError component (binary-co…
- Loading branch information
1 parent
a329487
commit 23ba639
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
packages/wallets/src/components/WalletError/__tests__/WalletError.spec.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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { ModalProvider } from '../../ModalProvider'; | ||
import WalletError from '../WalletError'; | ||
|
||
const mockModalHide = jest.fn(); | ||
jest.mock('../../ModalProvider', () => ({ | ||
...jest.requireActual('../../ModalProvider'), | ||
useModal: jest.fn(() => ({ | ||
...jest.requireActual('../../ModalProvider').useModal(), | ||
hide: mockModalHide, | ||
})), | ||
})); | ||
|
||
describe('WalletError', () => { | ||
it('should show error message and the title', () => { | ||
render( | ||
<ModalProvider> | ||
<WalletError errorMessage='Error message' title='Something went wrong!' /> | ||
</ModalProvider> | ||
); | ||
expect(screen.getByText('Error message')).toBeInTheDocument(); | ||
expect(screen.getByText('Something went wrong!')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call hide modal when close button is clicked', () => { | ||
render( | ||
<ModalProvider> | ||
<WalletError buttonText='Close' errorMessage='Error message' onClick={mockModalHide} /> | ||
</ModalProvider> | ||
); | ||
const closeButton = screen.getByRole('button', { name: 'Close' }); | ||
closeButton.click(); | ||
expect(mockModalHide).toHaveBeenCalled(); | ||
}); | ||
}); |