Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Migrate tests to vue-test-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
cristijora committed Oct 2, 2017
1 parent 910b9f3 commit 9d568ed
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
30 changes: 15 additions & 15 deletions test/unit/specs/FormWizard.spec.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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')
Expand All @@ -49,17 +49,17 @@ 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()
})
})
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) => {
Expand All @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 9d568ed

Please sign in to comment.