Full-Stack Web Development with Vue.js and Node

(singke) #1
Testing an MEVN Application Chapter 9

expect(vm.years).to.eql(['2018', '2017', '2016', '2015'])
})
})

This test states that the years variable should have the given values, which is ['2018',


'2017', '2016', '2015'].


Let's add another test to check whether the required methods exist in our vue


component, AddMovie.js, or not. Replace the contents in AddMovie.spec.js with the


following code:


import Vue from 'vue';
import AddMovie from '@/components/AddMovie';

describe('AddMovie', () => {
let cmp, vm;

beforeEach(() => {
cmp = Vue.extend(AddMovie);
vm = new cmp({
data: {
years: ['2018', '2017', '2016', '2015']
}
}).$mount()
})

it('equals years to ["2018", "2017", "2016", "2015"]', () => {
console.log(vm.years);
expect(vm.years).to.eql(['2018', '2017', '2016', '2015'])
})

it('has a submit() method', () => {
assert.deepEqual(typeof vm.submit, 'function')
})

it('has a clear() method', () => {
assert.deepEqual(typeof vm.clear, 'function')
})
})

Now, let's run the tests with the following command:


$ npm run unit
Free download pdf