Created
January 20, 2020 13:41
-
-
Save asoglovo/72c8ca381e5f2377c697428723a26a4c to your computer and use it in GitHub Desktop.
Test for the PaymentWithCard component
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
import testWrapperBuilder from './PaymentWithCard.spec.factory' | |
import api from '@/api/paymentAPI' | |
jest.mock('@/api/paymentAPI', function() { | |
return { pay: jest.fn() } | |
}) | |
describe('Payment with card', () => { | |
beforeEach(() => { | |
jest.clearAllMocks() | |
}) | |
it('should display a success message when the payment succeeds', () => { | |
api.pay.mockReturnValue({ ok: true }) | |
const successMessageSpy = jest.fn() | |
let wrapper = testWrapperBuilder() | |
.with.cardInfo('12345', 'Hari Seldon', '11/23') | |
.spy.successMsg(successMessageSpy) | |
.build() | |
wrapper.find('[data-qa="pay-btn"]').trigger('click') | |
expect(successMessageSpy).toHaveBeenCalledTimes(1) | |
}) | |
it('should display an error message when the payment fails', () => { | |
api.pay.mockReturnValue({ ok: false }) | |
const errorMessageSpy = jest.fn() | |
let wrapper = testWrapperBuilder() | |
.with.cardInfo('12345', 'Hari Seldon', '11/23') | |
.spy.errorMsg(errorMessageSpy) | |
.build() | |
wrapper.find('[data-qa="pay-btn"]').trigger('click') | |
expect(errorMessageSpy).toHaveBeenCalledTimes(1) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment