From 9d568edff4ffe653a199f640b2f324c8b5b513e9 Mon Sep 17 00:00:00 2001 From: cristijora Date: Mon, 2 Oct 2017 19:34:11 +0300 Subject: [PATCH] Migrate tests to vue-test-utils --- package.json | 2 +- test/unit/specs/FormWizard.spec.js | 30 +++++++++++++++--------------- yarn.lock | 6 ++++++ 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 819c923..d9398f7 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ }, "devDependencies": { "autoprefixer": "^6.7.2", - "avoriaz": "^4.1.0", "babel-core": "^6.22.1", "babel-eslint": "^7.1.1", "babel-loader": "^6.2.10", @@ -95,6 +94,7 @@ "vue-router": "^2.5.1", "vue-style-loader": "^2.0.0", "vue-template-compiler": "^2.4.2", + "vue-test-utils": "^1.0.0-beta.1", "webpack": "^2.2.1", "webpack-bundle-analyzer": "^2.2.1", "webpack-dev-middleware": "^1.10.0", diff --git a/test/unit/specs/FormWizard.spec.js b/test/unit/specs/FormWizard.spec.js index ed3368e..ca59114 100644 --- a/test/unit/specs/FormWizard.spec.js +++ b/test/unit/specs/FormWizard.spec.js @@ -1,7 +1,7 @@ import Vue from 'vue' import VueFormWizard from './../../../src/index' import {TabContent as WizardTab, WizardStep, FormWizard} from './../../../src/index' -import {mount} from 'avoriaz' +import {mount} from 'vue-test-utils' import sinon from 'sinon' Vue.use(VueFormWizard) @@ -35,11 +35,11 @@ describe('FormWizard.vue', () => { it('renders steps', (done) => { const wizard = mount(twoStepWizard) Vue.nextTick(() => { - const steps = wizard.find(WizardStep) - const firsStep = steps[0] + const steps = wizard.findAll(WizardStep) + const firsStep = steps.at(0) expect(steps.length).to.equal(3) expect(firsStep.hasClass('active')) - const stepTitle = firsStep.find('.stepTitle')[0] + const stepTitle = firsStep.find('.stepTitle') expect(stepTitle.is('span')).to.equal(true) const stepText = stepTitle.text().trim() expect(stepText).to.equal('Personal details') @@ -49,7 +49,7 @@ describe('FormWizard.vue', () => { it('renders tabs', (done) => { const wizard = mount(twoStepWizard) Vue.nextTick(() => { - const tabs = wizard.find(WizardTab) + const tabs = wizard.findAll(WizardTab) expect(tabs.length).to.equal(3) done() }) @@ -57,9 +57,9 @@ describe('FormWizard.vue', () => { it('displays only one tab', (done) => { const wizard = mount(twoStepWizard) Vue.nextTick(() => { - const tabs = wizard.find(WizardTab) - const activeTabs = tabs.filter((tab) => tab.data().active) - const inactiveTabs = tabs.filter((tab) => !tab.data().active) + const tabs = wizard.findAll(WizardTab).wrappers + const activeTabs = tabs.filter((tab) => tab.vm.active) + const inactiveTabs = tabs.filter((tab) => !tab.vm.active) expect(activeTabs.length).to.equal(1) inactiveTabs.forEach((tab) => { @@ -71,21 +71,21 @@ describe('FormWizard.vue', () => { it('starts at a given index', (done) => { const wizard = mount(twoStepWizard) Vue.nextTick(() => { - const tabs = wizard.find(WizardTab) - const activeTab = tabs[startIndex] - expect(activeTab.data().active).to.equal(true) - const formWizard = wizard.find(FormWizard)[0] - expect(formWizard.data().activeTabIndex).to.equal(startIndex) + const tabs = wizard.findAll(WizardTab) + const activeTab = tabs.at(startIndex) + expect(activeTab.vm.active).to.equal(true) + const formWizard = wizard.find(FormWizard) + expect(formWizard.vm.activeTabIndex).to.equal(startIndex) done() }) }) it('next tab is called', (done) => { const wizard = mount(twoStepWizard) const nextTabHandler = sinon.stub() - const formWizard = wizard.find(FormWizard)[0] + const formWizard = wizard.find(FormWizard) formWizard.setMethods({nextTab: nextTabHandler}) Vue.nextTick(() => { - const nextButton = wizard.find('.wizard-footer-right span')[0] + const nextButton = wizard.find('.wizard-footer-right span') nextButton.trigger('click') expect(nextTabHandler.called).to.equal(true) done() diff --git a/yarn.lock b/yarn.lock index 8f652aa..9e74a3a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5978,6 +5978,12 @@ vue-template-es2015-compiler@^1.2.2: version "1.5.3" resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.5.3.tgz#22787de4e37ebd9339b74223bc467d1adee30545" +vue-test-utils@^1.0.0-beta.1: + version "1.0.0-beta.1" + resolved "https://registry.yarnpkg.com/vue-test-utils/-/vue-test-utils-1.0.0-beta.1.tgz#a3c6450d64f084190b92b22f84626e53191ba32b" + dependencies: + lodash "^4.17.4" + vue@^2.4.2: version "2.4.2" resolved "https://registry.yarnpkg.com/vue/-/vue-2.4.2.tgz#a9855261f191c978cc0dc1150531b8d08149b58c"