Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dive into vue-test-utils ~~Road of 1.0.0~~

Dive into vue-test-utils ~~Road of 1.0.0~~

pipopotamasu

June 24, 2019
Tweet

More Decks by pipopotamasu

Other Decks in Technology

Transcript

  1. Dive into vue-test-utils ~~ Road of major 1.0.0 ~~ Yamato

    Murakami (@pipopotamasu3) Vue.js Tokyo Drinkup#3 06/24/2019
  2. So, what is medpacker? vue-test-utils is … vue-test-utils is the

    “official” unit testing library for Vue.js
  3. extended components? // use Vue.extend const BaseComponent = Vue.extend({ data

    () { return { lastname: 'murakami' } } }) new BaseComponent({ el: '#app', template: '<span>{{ firstname }}-{{ lastname }}</span>', data () { return { firstname: 'yamato' } } })
  4. extended components? // use extends property const BaseComponent = {

    data () { return { lastname: 'murakami' } } } new Vue({ extends: BaseComponent, el: '#app', template: '<span>{{ firstname }}-{{ lastname }}</span>', data () { return { firstname: 'yamato' } } });
  5. extended components? const BaseComponent = Vue.extend({ data () { return

    { lastname: 'murakami' } } }) const ChildCompoent = BaseComponent.extend({ template: '<span>{{ firstname }}-{{ lastname }}</span>', data () { return { firstname: 'yamato' } } }) describe("ChildCompoent.vue", () => { it("renders fullname", () => { const wrapper = mount(ChildCompoent); expect(wrapper.text()).toMatch('yamato-murakami'); }); });
  6. // use Vue.extend const BaseComponent = Vue.extend({ data () {

    return { lastname: 'murakami' } } }) BaseComponent.extend({ ~~~~~~~~~ some extend setting ~~~~~~~~~ })
  7. // use Vue.extend const BaseComponent = Vue.extend({ data () {

    return { lastname: 'murakami' } } }) BaseComponent.extend({ ~~~~~~~~~ some extend setting ~~~~~~~~~ }) "
  8. Why call `extend` twice? const Component = { template: '<span></span>',

    computed: { returnZero () { return 0; } } } describe("Component.vue", () => { it("override", () => { const wrapper = mount(Component, { computed: { returnZero () { return 'Override!!' } } }); expect(wrapper.vm.returnZero).toBe('Override!!'); }); });
  9. Reference Images • http://hermie.jp/ • Yoshiki HAYAMA hermie.jp • CC

    BY 3.0 • https://creativecommons.org/licenses/by/ 3.0/deed.ja