Created
January 20, 2020 13:44
-
-
Save asoglovo/e6d656e014314853c9f3f28bbdc15559 to your computer and use it in GitHub Desktop.
Using the builder pattern to mount Vue component wrappers
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 { shallowMount } from '@vue/test-utils' | |
import PaymentWithCard from '@/components/PaymentWithCard.vue' | |
export default function() { | |
let amountInEuros = 100 | |
let cardNumber = null, | |
cardHolder = null, | |
expirationDate = null | |
let successMsgSpy = jest.fn() | |
let errorMsgSpy = jest.fn() | |
const builder = { | |
with: { | |
amountInEuros(amount) { | |
amountInEuros = amount | |
return builder | |
}, | |
cardInfo(number, holder, expiration) { | |
cardNumber = number | |
cardHolder = holder | |
expirationDate = expiration | |
return builder | |
} | |
}, | |
spy: { | |
successMsg(spy) { | |
successMsgSpy = spy | |
return builder | |
}, | |
errorMsg(spy) { | |
errorMsgSpy = spy | |
return builder | |
} | |
}, | |
build() { | |
return shallowMount(PaymentWithCard, { | |
propsData: { amountInEuros, cardNumber, cardHolder, expirationDate }, | |
mocks: { | |
$successMessage: successMsgSpy, | |
$errorMessage: errorMsgSpy | |
}, | |
stubs: ['el-card', 'el-input', 'el-button'] | |
}) | |
} | |
} | |
return builder | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment