')
})
@@ -144,49 +147,71 @@ describeWithMountingMethods('options.stub', (mountingMethod) => {
render: h => h('registered-component')
}
const invalidValues = [{}, [], 3]
- const error = '[vue-test-utils]: each item in an options.stubs array must be a string'
+ const error =
+ '[vue-test-utils]: each item in an options.stubs array must be a string'
invalidValues.forEach(invalidValue => {
- const fn = () => mountingMethod(ComponentWithGlobalComponent, {
- stubs: [invalidValue]
- })
- expect(fn).to.throw().with.property('message', error)
+ const fn = () =>
+ mountingMethod(ComponentWithGlobalComponent, {
+ stubs: [invalidValue]
+ })
+ expect(fn)
+ .to.throw()
+ .with.property('message', error)
})
})
it('throws error if passed string in object when vue-template-compiler is undefined', () => {
- const compilerSave = require.cache[require.resolve('vue-template-compiler')].exports.compileToFunctions
- require.cache[require.resolve('vue-template-compiler')].exports.compileToFunctions = undefined
+ const compilerSave =
+ require.cache[require.resolve('vue-template-compiler')].exports
+ .compileToFunctions
+ require.cache[
+ require.resolve('vue-template-compiler')
+ ].exports.compileToFunctions = undefined
delete require.cache[require.resolve('../../../packages/test-utils')]
- delete require.cache[require.resolve('../../../packages/server-test-utils')]
- const mountingMethodFresh = mountingMethod.name === 'renderToString'
- ? require('../../../packages/server-test-utils').renderToString
- : require('../../../packages/test-utils')[mountingMethod.name]
- const message = '[vue-test-utils]: vueTemplateCompiler is undefined, you must pass precompiled components if vue-template-compiler is undefined'
- const fn = () => mountingMethodFresh(Component, {
- stubs: {
- ChildComponent: ''
- }
- })
+ delete require.cache[
+ require.resolve('../../../packages/server-test-utils')
+ ]
+ const mountingMethodFresh =
+ mountingMethod.name === 'renderToString'
+ ? require('../../../packages/server-test-utils').renderToString
+ : require('../../../packages/test-utils')[mountingMethod.name]
+ const message =
+ '[vue-test-utils]: vueTemplateCompiler is undefined, you must pass precompiled components if vue-template-compiler is undefined'
+ const fn = () =>
+ mountingMethodFresh(Component, {
+ stubs: {
+ ChildComponent: ''
+ }
+ })
try {
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
} catch (err) {
- require.cache[require.resolve('vue-template-compiler')].exports.compileToFunctions = compilerSave
+ require.cache[
+ require.resolve('vue-template-compiler')
+ ].exports.compileToFunctions = compilerSave
throw err
}
- require.cache[require.resolve('vue-template-compiler')].exports.compileToFunctions = compilerSave
+ require.cache[
+ require.resolve('vue-template-compiler')
+ ].exports.compileToFunctions = compilerSave
})
- itDoNotRunIf(mountingMethod.name === 'shallowMount',
- 'does not stub component when set to false', () => {
+ itDoNotRunIf(
+ mountingMethod.name === 'shallowMount',
+ 'does not stub component when set to false',
+ () => {
const wrapper = mountingMethod(ComponentWithChild, {
stubs: {
ChildComponent: false
- }})
- const HTML = mountingMethod.name === 'renderToString'
- ? wrapper
- : wrapper.html()
+ }
+ })
+ const HTML =
+ mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
expect(HTML).to.contain('')
- })
+ }
+ )
it('combines with stubs from config', () => {
const localVue = createLocalVue()
@@ -202,10 +227,7 @@ describeWithMountingMethods('options.stub', (mountingMethod) => {
localVue.component('span-component', SpanComponent)
localVue.component('time-component', TimeComponent)
const TestComponent = {
- render: h => h('div', [
- h('span-component'),
- h('time-component')
- ])
+ render: h => h('div', [h('span-component'), h('time-component')])
}
const wrapper = mountingMethod(TestComponent, {
@@ -214,9 +236,8 @@ describeWithMountingMethods('options.stub', (mountingMethod) => {
},
localVue
})
- const HTML = mountingMethod.name === 'renderToString'
- ? wrapper
- : wrapper.html()
+ const HTML =
+ mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
expect(HTML).to.contain('
')
expect(HTML).to.contain('')
})
@@ -229,9 +250,7 @@ describeWithMountingMethods('options.stub', (mountingMethod) => {
}
localVue.component('time-component', TimeComponent)
const TestComponent = {
- render: h => h('div', [
- h('time-component')
- ])
+ render: h => h('div', [h('time-component')])
}
const wrapper = mountingMethod(TestComponent, {
@@ -240,28 +259,32 @@ describeWithMountingMethods('options.stub', (mountingMethod) => {
},
localVue
})
- const HTML = mountingMethod.name === 'renderToString'
- ? wrapper
- : wrapper.html()
+ const HTML =
+ mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
expect(HTML).to.contain('')
})
itDoNotRunIf(
mountingMethod.name === 'shallowMount' ||
- mountingMethod.name === 'renderToString',
- 'stubs on child components', () => {
+ mountingMethod.name === 'renderToString',
+ 'stubs on child components',
+ () => {
const TestComponent = {
template: ''
}
- const wrapper = mountingMethod({
- components: { 'test-component': TestComponent },
- template: ''
- }, {
- stubs: ['transition']
- })
+ const wrapper = mountingMethod(
+ {
+ components: { 'test-component': TestComponent },
+ template: ''
+ },
+ {
+ stubs: ['transition']
+ }
+ )
expect(wrapper.find('span').exists()).to.equal(false)
- })
+ }
+ )
it('converts config to array if stubs is an array', () => {
const localVue = createLocalVue()
@@ -272,9 +295,7 @@ describeWithMountingMethods('options.stub', (mountingMethod) => {
}
localVue.component('time-component', TimeComponent)
const TestComponent = {
- render: h => h('div', [
- h('time-component')
- ])
+ render: h => h('div', [h('time-component')])
}
const wrapper = mountingMethod(TestComponent, {
@@ -282,9 +303,8 @@ describeWithMountingMethods('options.stub', (mountingMethod) => {
localVue
})
- const HTML = mountingMethod.name === 'renderToString'
- ? wrapper
- : wrapper.html()
+ const HTML =
+ mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
expect(HTML).to.contain('')
})
@@ -308,9 +328,8 @@ describeWithMountingMethods('options.stub', (mountingMethod) => {
'stub-component': StubComponent
}
})
- const HTML = mountingMethod.name === 'renderToString'
- ? wrapper
- : wrapper.html()
+ const HTML =
+ mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
expect(HTML).contains('No render function')
})
@@ -330,33 +349,44 @@ describeWithMountingMethods('options.stub', (mountingMethod) => {
'',
''
]
- const error = '[vue-test-utils]: options.stub cannot contain a circular reference'
- names.forEach((name) => {
+ const error =
+ '[vue-test-utils]: options.stub cannot contain a circular reference'
+ names.forEach(name => {
invalidValues.forEach(invalidValue => {
- const fn = () => mountingMethod(ComponentWithChild, {
- stubs: {
- ChildComponent: invalidValue.replace(/NAME/g, name)
- }})
- expect(fn).to.throw().with.property('message', error)
+ const fn = () =>
+ mountingMethod(ComponentWithChild, {
+ stubs: {
+ ChildComponent: invalidValue.replace(/NAME/g, name)
+ }
+ })
+ expect(fn)
+ .to.throw()
+ .with.property('message', error)
})
- validValues.forEach((validValue) => {
+ validValues.forEach(validValue => {
mountingMethod(ComponentWithChild, {
stubs: {
ChildComponent: validValue.replace(/NAME/g, name)
- }})
+ }
+ })
})
})
})
it('throws an error when passed an invalid value as stub', () => {
- const error = '[vue-test-utils]: options.stub values must be passed a string or component'
+ const error =
+ '[vue-test-utils]: options.stub values must be passed a string or component'
const invalidValues = [1, null, [], {}, NaN]
invalidValues.forEach(invalidValue => {
- const fn = () => mountingMethod(ComponentWithChild, {
- stubs: {
- ChildComponent: invalidValue
- }})
- expect(fn).to.throw().with.property('message', error)
+ const fn = () =>
+ mountingMethod(ComponentWithChild, {
+ stubs: {
+ ChildComponent: invalidValue
+ }
+ })
+ expect(fn)
+ .to.throw()
+ .with.property('message', error)
})
})
})
diff --git a/test/specs/mounting-options/sync.spec.js b/test/specs/mounting-options/sync.spec.js
index 2268c4e0b..fab7cc3d7 100644
--- a/test/specs/mounting-options/sync.spec.js
+++ b/test/specs/mounting-options/sync.spec.js
@@ -1,7 +1,7 @@
import sinon from 'sinon'
import { describeWithShallowAndMount } from '~resources/utils'
-describeWithShallowAndMount('options.sync', (mountingMethod) => {
+describeWithShallowAndMount('options.sync', mountingMethod => {
it('sets watchers to sync if set to true', () => {
const TestComponent = {
template: '{{someData}}
',
@@ -91,7 +91,7 @@ describeWithShallowAndMount('options.sync', (mountingMethod) => {
expect(wrapper.vm.basket[0]).to.equal('foo')
})
- it('does not set watchers to sync if set to false', (done) => {
+ it('does not set watchers to sync if set to false', done => {
const TestComponent = {
template: '{{someData}}
',
data: () => ({
diff --git a/test/specs/renderToString.spec.js b/test/specs/renderToString.spec.js
index 60e398933..156df6132 100644
--- a/test/specs/renderToString.spec.js
+++ b/test/specs/renderToString.spec.js
@@ -4,10 +4,12 @@ import { isRunningJSDOM } from '~resources/utils'
import { itDoNotRunIf } from 'conditional-specs'
describe.skip('renderToString', () => {
- itDoNotRunIf(isRunningJSDOM,
- 'throws error when not run in node', () => {
- const fn = () => renderToString(Component)
- const message = '[vue-test-utils]: renderToString must be run in node. It cannot be run in a browser'
- expect(fn).to.throw().with.property('message', message)
- })
+ itDoNotRunIf(isRunningJSDOM, 'throws error when not run in node', () => {
+ const fn = () => renderToString(Component)
+ const message =
+ '[vue-test-utils]: renderToString must be run in node. It cannot be run in a browser'
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
+ })
})
diff --git a/test/specs/shallow-mount.spec.js b/test/specs/shallow-mount.spec.js
index d6baa1c82..41f75b41b 100644
--- a/test/specs/shallow-mount.spec.js
+++ b/test/specs/shallow-mount.spec.js
@@ -11,238 +11,243 @@ import RecursiveComponent from '~resources/components/recursive-component.vue'
import { vueVersion } from '~resources/utils'
import { describeRunIf, itDoNotRunIf } from 'conditional-specs'
-describeRunIf(process.env.TEST_ENV !== 'node',
- 'shallowMount', () => {
- beforeEach(() => {
- sinon.stub(console, 'info')
- sinon.stub(console, 'error')
- })
-
- afterEach(() => {
- console.info.restore()
- console.error.restore()
- })
-
- it('returns new VueWrapper of Vue localVue if no options are passed', () => {
- const compiled = compileToFunctions('')
- const wrapper = shallowMount(compiled)
- expect(wrapper.isVueInstance()).to.equal(true)
- expect(wrapper.vm).to.be.an('object')
- })
-
- it('returns new VueWrapper of Vue localVue with all children stubbed', () => {
- const wrapper = shallowMount(ComponentWithNestedChildren)
- expect(wrapper.isVueInstance()).to.equal(true)
- expect(wrapper.findAll(Component).length).to.equal(0)
- expect(wrapper.findAll(ComponentWithChild).length).to.equal(1)
- })
-
- it('returns new VueWrapper of Vue localVue with all children stubbed', () => {
- const wrapper = shallowMount(ComponentWithNestedChildren)
- expect(wrapper.isVueInstance()).to.equal(true)
- expect(wrapper.findAll(Component).length).to.equal(0)
- expect(wrapper.findAll(ComponentWithChild).length).to.equal(1)
- })
-
- it('does not modify component directly', () => {
- const wrapper = shallowMount(ComponentWithNestedChildren)
- expect(wrapper.findAll(Component).length).to.equal(0)
- const mountedWrapper = mount(ComponentWithNestedChildren)
- expect(mountedWrapper.findAll(Component).length).to.equal(1)
- })
-
- it('stubs globally registered components when options.localVue is provided', () => {
- const localVue = Vue.extend()
- localVue.component('registered-component', ComponentWithLifecycleHooks)
- const TestComponent = {
- render: h => h('registered-component')
- }
- shallowMount(TestComponent, { localVue })
- localVue.component('registered-component', ComponentWithLifecycleHooks)
- mount(TestComponent, { localVue })
+describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
+ beforeEach(() => {
+ sinon.stub(console, 'info')
+ sinon.stub(console, 'error')
+ })
- expect(console.info.callCount).to.equal(4)
- })
+ afterEach(() => {
+ console.info.restore()
+ console.error.restore()
+ })
- it('stubs globally registered components', () => {
- Vue.component('registered-component', ComponentWithLifecycleHooks)
- const Component = {
- render: h => h('registered-component')
- }
- shallowMount(Component)
- mount(Component)
+ it('returns new VueWrapper of Vue localVue if no options are passed', () => {
+ const compiled = compileToFunctions('')
+ const wrapper = shallowMount(compiled)
+ expect(wrapper.isVueInstance()).to.equal(true)
+ expect(wrapper.vm).to.be.an('object')
+ })
- expect(console.info.callCount).to.equal(4)
- })
+ it('returns new VueWrapper of Vue localVue with all children stubbed', () => {
+ const wrapper = shallowMount(ComponentWithNestedChildren)
+ expect(wrapper.isVueInstance()).to.equal(true)
+ expect(wrapper.findAll(Component).length).to.equal(0)
+ expect(wrapper.findAll(ComponentWithChild).length).to.equal(1)
+ })
- itDoNotRunIf(
- vueVersion < 2.1,
- 'adds stubbed components to ignored elements', () => {
- const TestComponent = {
- template: `
+ it('returns new VueWrapper of Vue localVue with all children stubbed', () => {
+ const wrapper = shallowMount(ComponentWithNestedChildren)
+ expect(wrapper.isVueInstance()).to.equal(true)
+ expect(wrapper.findAll(Component).length).to.equal(0)
+ expect(wrapper.findAll(ComponentWithChild).length).to.equal(1)
+ })
+
+ it('does not modify component directly', () => {
+ const wrapper = shallowMount(ComponentWithNestedChildren)
+ expect(wrapper.findAll(Component).length).to.equal(0)
+ const mountedWrapper = mount(ComponentWithNestedChildren)
+ expect(mountedWrapper.findAll(Component).length).to.equal(1)
+ })
+
+ it('stubs globally registered components when options.localVue is provided', () => {
+ const localVue = Vue.extend()
+ localVue.component('registered-component', ComponentWithLifecycleHooks)
+ const TestComponent = {
+ render: h => h('registered-component')
+ }
+ shallowMount(TestComponent, { localVue })
+ localVue.component('registered-component', ComponentWithLifecycleHooks)
+ mount(TestComponent, { localVue })
+
+ expect(console.info.callCount).to.equal(4)
+ })
+
+ it('stubs globally registered components', () => {
+ Vue.component('registered-component', ComponentWithLifecycleHooks)
+ const Component = {
+ render: h => h('registered-component')
+ }
+ shallowMount(Component)
+ mount(Component)
+
+ expect(console.info.callCount).to.equal(4)
+ })
+
+ itDoNotRunIf(
+ vueVersion < 2.1,
+ 'adds stubbed components to ignored elements',
+ () => {
+ const TestComponent = {
+ template: `
`,
- components: {
- 'router-link': {
- template: ''
- },
- 'custom-component': {
- template: ''
- }
+ components: {
+ 'router-link': {
+ template: ''
+ },
+ 'custom-component': {
+ template: ''
}
}
- shallowMount(TestComponent)
- expect(console.error).not.called
- })
-
- itDoNotRunIf(
- vueVersion < 2.1,
- 'handles recursive components', () => {
- const TestComponent = {
- template: `
+ }
+ shallowMount(TestComponent)
+ expect(console.error).not.called
+ }
+ )
+
+ itDoNotRunIf(vueVersion < 2.1, 'handles recursive components', () => {
+ const TestComponent = {
+ template: `
`,
- name: 'test-component'
- }
- const wrapper = shallowMount(TestComponent)
- expect(wrapper.html()).to.contain('')
- expect(console.error).not.called
- })
+ name: 'test-component'
+ }
+ const wrapper = shallowMount(TestComponent)
+ expect(wrapper.html()).to.contain('')
+ expect(console.error).not.called
+ })
- it('does not call stubbed children lifecycle hooks', () => {
- shallowMount(ComponentWithNestedChildren)
- expect(console.info.called).to.equal(false)
- })
+ it('does not call stubbed children lifecycle hooks', () => {
+ shallowMount(ComponentWithNestedChildren)
+ expect(console.info.called).to.equal(false)
+ })
- it('stubs extended components', () => {
- const ComponentWithPTag = {
- template: ``
- }
- const BaseComponent = {
- template: `
+ it('stubs extended components', () => {
+ const ComponentWithPTag = {
+ template: ``
+ }
+ const BaseComponent = {
+ template: `
`,
- components: {
- ComponentWithPTag
- }
+ components: {
+ ComponentWithPTag
}
+ }
- const TestComponent = {
- extends: BaseComponent
- }
+ const TestComponent = {
+ extends: BaseComponent
+ }
- const wrapper = shallowMount(TestComponent)
- expect(wrapper.find(ComponentWithPTag).exists()).to.equal(true)
- expect(wrapper.find('p').exists()).to.equal(false)
- })
+ const wrapper = shallowMount(TestComponent)
+ expect(wrapper.find(ComponentWithPTag).exists()).to.equal(true)
+ expect(wrapper.find('p').exists()).to.equal(false)
+ })
- it('stubs nested extended components', () => {
- const ComponentWithPTag = {
- template: ``
- }
- const BaseComponent = {
- template: `
+ it('stubs nested extended components', () => {
+ const ComponentWithPTag = {
+ template: ``
+ }
+ const BaseComponent = {
+ template: `
`,
- components: {
- ComponentWithPTag
- }
+ components: {
+ ComponentWithPTag
}
+ }
- const ExtendedBaseComponent = {
- extends: BaseComponent
- }
+ const ExtendedBaseComponent = {
+ extends: BaseComponent
+ }
- const TestComponent = {
- extends: ExtendedBaseComponent
- }
+ const TestComponent = {
+ extends: ExtendedBaseComponent
+ }
- const wrapper = shallowMount(TestComponent)
- expect(wrapper.find(ComponentWithPTag).exists()).to.equal(true)
- expect(wrapper.find('p').exists()).to.equal(false)
- })
+ const wrapper = shallowMount(TestComponent)
+ expect(wrapper.find(ComponentWithPTag).exists()).to.equal(true)
+ expect(wrapper.find('p').exists()).to.equal(false)
+ })
- it('stubs Vue class component children', () => {
- if (vueVersion < 2.3) {
- return
- }
- const wrapper = shallowMount(ComponentAsAClassWithChild)
- expect(wrapper.find(Component).exists()).to.equal(true)
- expect(wrapper.findAll('div').length).to.equal(1)
- })
+ it('stubs Vue class component children', () => {
+ if (vueVersion < 2.3) {
+ return
+ }
+ const wrapper = shallowMount(ComponentAsAClassWithChild)
+ expect(wrapper.find(Component).exists()).to.equal(true)
+ expect(wrapper.findAll('div').length).to.equal(1)
+ })
- it('works correctly with find, contains, findAll, and is on unnamed components', () => {
- const TestComponent = {
- template: `
+ it('works correctly with find, contains, findAll, and is on unnamed components', () => {
+ const TestComponent = {
+ template: `
`,
- components: {
- ComponentWithoutName
- }
+ components: {
+ ComponentWithoutName
}
- const wrapper = shallowMount(TestComponent)
- expect(wrapper.contains(ComponentWithoutName)).to.equal(true)
- expect(wrapper.find(ComponentWithoutName).exists()).to.equal(true)
- expect(wrapper.findAll(ComponentWithoutName).length).to.equal(1)
- })
+ }
+ const wrapper = shallowMount(TestComponent)
+ expect(wrapper.contains(ComponentWithoutName)).to.equal(true)
+ expect(wrapper.find(ComponentWithoutName).exists()).to.equal(true)
+ expect(wrapper.findAll(ComponentWithoutName).length).to.equal(1)
+ })
- it('works correctly with find, contains, findAll, and is on named components', () => {
- const TestComponent = {
- template: `
+ it('works correctly with find, contains, findAll, and is on named components', () => {
+ const TestComponent = {
+ template: `
`,
- components: {
- AComponent: Component
- }
+ components: {
+ AComponent: Component
}
- const wrapper = shallowMount(TestComponent)
- expect(wrapper.contains(Component)).to.equal(true)
- expect(wrapper.find(Component).exists()).to.equal(true)
- expect(wrapper.findAll(Component).length).to.equal(1)
- })
+ }
+ const wrapper = shallowMount(TestComponent)
+ expect(wrapper.contains(Component)).to.equal(true)
+ expect(wrapper.find(Component).exists()).to.equal(true)
+ expect(wrapper.findAll(Component).length).to.equal(1)
+ })
- it('works correctly with find on recursive components', () => {
+ it('works correctly with find on recursive components', () => {
// this is for a bug that I've been unable to replicate.
// Sometimes components mutate their components, in this line—
- RecursiveComponent.components = {
- RecursiveComponent: { render: h => h('div') }
- }
+ RecursiveComponent.components = {
+ RecursiveComponent: { render: h => h('div') }
+ }
- expect(shallowMount(RecursiveComponent, {
+ expect(
+ shallowMount(RecursiveComponent, {
propsData: {
items: ['', '']
}
- }).findAll(RecursiveComponent).length).to.equal(3)
- RecursiveComponent.components = {
- 'recursive-component': { render: h => h('div') }
- }
- expect(shallowMount(RecursiveComponent, {
+ }).findAll(RecursiveComponent).length
+ ).to.equal(3)
+ RecursiveComponent.components = {
+ 'recursive-component': { render: h => h('div') }
+ }
+ expect(
+ shallowMount(RecursiveComponent, {
propsData: {
items: ['', '']
}
- }).findAll(RecursiveComponent).length).to.equal(3)
- })
+ }).findAll(RecursiveComponent).length
+ ).to.equal(3)
+ })
- it('throws an error when the component fails to mount', () => {
- expect(() => shallowMount({
+ it('throws an error when the component fails to mount', () => {
+ expect(() =>
+ shallowMount({
template: '',
mounted: function () {
- throw (new Error('Error'))
+ throw new Error('Error')
}
- })).to.throw()
- })
+ })
+ ).to.throw()
})
+})
diff --git a/test/specs/wrapper-array.spec.js b/test/specs/wrapper-array.spec.js
index 50d3b6da6..dbd0217e2 100644
--- a/test/specs/wrapper-array.spec.js
+++ b/test/specs/wrapper-array.spec.js
@@ -1,7 +1,7 @@
import { compileToFunctions } from 'vue-template-compiler'
import { describeWithShallowAndMount } from '~resources/utils'
-describeWithShallowAndMount('WrapperArray', (mountingMethod) => {
+describeWithShallowAndMount('WrapperArray', mountingMethod => {
function getWrapperArray (wrappers) {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
@@ -26,15 +26,43 @@ describeWithShallowAndMount('WrapperArray', (mountingMethod) => {
it('returns filtered wrapper when filter is called', () => {
const wrapperArray = getWrapperArray()
- expect(wrapperArray.filter(w => {
- return w.text() !== '2'
- }).length).to.equal(2)
+ expect(
+ wrapperArray.filter(w => {
+ return w.text() !== '2'
+ }).length
+ ).to.equal(2)
})
- const methods = ['at', 'attributes', 'classes', 'contains', 'emitted', 'emittedByOrder', 'hasAttribute',
- 'hasClass', 'hasProp', 'hasStyle', 'find', 'findAll', 'html', 'text', 'is', 'isEmpty', 'isVisible', 'isVueInstance',
- 'name', 'props', 'setComputed', 'setMethods', 'setData', 'setProps', 'trigger', 'update', 'destroy']
- methods.forEach((method) => {
+ const methods = [
+ 'at',
+ 'attributes',
+ 'classes',
+ 'contains',
+ 'emitted',
+ 'emittedByOrder',
+ 'hasAttribute',
+ 'hasClass',
+ 'hasProp',
+ 'hasStyle',
+ 'find',
+ 'findAll',
+ 'html',
+ 'text',
+ 'is',
+ 'isEmpty',
+ 'isVisible',
+ 'isVueInstance',
+ 'name',
+ 'props',
+ 'setComputed',
+ 'setMethods',
+ 'setData',
+ 'setProps',
+ 'trigger',
+ 'update',
+ 'destroy'
+ ]
+ methods.forEach(method => {
it(`throws error if ${method} is called when there are no items in wrapper array`, () => {
if (method === 'at') {
return
@@ -42,24 +70,47 @@ describeWithShallowAndMount('WrapperArray', (mountingMethod) => {
const wrapperArray = getWrapperArray()
wrapperArray.wrappers = []
const message = `[vue-test-utils]: ${method} cannot be called on 0 items`
- expect(() => wrapperArray[method]()).to.throw().with.property('message', message)
+ expect(() => wrapperArray[method]())
+ .to.throw()
+ .with.property('message', message)
})
it(`${method} throws error if called when there are items in wrapper array`, () => {
- if (['at', 'contains', 'hasAttribute', 'hasClass', 'hasProp', 'hasStyle', 'is', 'isEmpty', 'isVisible', 'isVueInstance',
- 'setComputed', 'setMethods', 'setData', 'setProps', 'trigger', 'update', 'destroy'].includes(method)) {
+ if (
+ [
+ 'at',
+ 'contains',
+ 'hasAttribute',
+ 'hasClass',
+ 'hasProp',
+ 'hasStyle',
+ 'is',
+ 'isEmpty',
+ 'isVisible',
+ 'isVueInstance',
+ 'setComputed',
+ 'setMethods',
+ 'setData',
+ 'setProps',
+ 'trigger',
+ 'update',
+ 'destroy'
+ ].includes(method)
+ ) {
return
}
const wrapperArray = getWrapperArray()
wrapperArray.wrappers = [1, 2, 3]
const message = `[vue-test-utils]: ${method} must be called on a single wrapper, use at(i) to access a wrapper`
- expect(() => wrapperArray[method]()).to.throw().with.property('message', message)
+ expect(() => wrapperArray[method]())
+ .to.throw()
+ .with.property('message', message)
})
})
it('exists returns true if it has every existing wrappers', () => {
const wrapperArray = getWrapperArray()
- wrapperArray.wrappers.forEach((w) => {
+ wrapperArray.wrappers.forEach(w => {
expect(w.exists()).to.equal(true)
})
expect(wrapperArray.exists()).to.equal(true)
@@ -94,7 +145,10 @@ describeWithShallowAndMount('WrapperArray', (mountingMethod) => {
})
it('contains returns false if not every wrapper.contains() returns true', () => {
- const wrapperArray = getWrapperArray([{ contains: () => true }, { contains: () => false }])
+ const wrapperArray = getWrapperArray([
+ { contains: () => true },
+ { contains: () => false }
+ ])
expect(wrapperArray.contains()).to.equal(false)
})
@@ -108,7 +162,10 @@ describeWithShallowAndMount('WrapperArray', (mountingMethod) => {
})
it('hasAttribute returns false if not every wrapper.hasAttribute() returns true', () => {
- const wrapperArray = getWrapperArray([{ hasAttribute: () => true }, { hasAttribute: () => false }])
+ const wrapperArray = getWrapperArray([
+ { hasAttribute: () => true },
+ { hasAttribute: () => false }
+ ])
expect(wrapperArray.hasAttribute('attribute', 'value')).to.equal(false)
})
@@ -121,7 +178,10 @@ describeWithShallowAndMount('WrapperArray', (mountingMethod) => {
})
it('hasClass returns false if not every wrapper.hasClass() returns true', () => {
- const wrapperArray = getWrapperArray([{ hasClass: () => true }, { hasClass: () => false }])
+ const wrapperArray = getWrapperArray([
+ { hasClass: () => true },
+ { hasClass: () => false }
+ ])
expect(wrapperArray.hasClass('class')).to.equal(false)
})
@@ -135,7 +195,10 @@ describeWithShallowAndMount('WrapperArray', (mountingMethod) => {
})
it('hasProp returns false if not every wrapper.hasProp() returns true', () => {
- const wrapperArray = getWrapperArray([{ hasProp: () => true }, { hasProp: () => false }])
+ const wrapperArray = getWrapperArray([
+ { hasProp: () => true },
+ { hasProp: () => false }
+ ])
expect(wrapperArray.hasProp('prop', 'value')).to.equal(false)
})
@@ -149,7 +212,10 @@ describeWithShallowAndMount('WrapperArray', (mountingMethod) => {
})
it('hasStyle returns false if not every wrapper.hasStyle() returns true', () => {
- const wrapperArray = getWrapperArray([{ hasStyle: () => true }, { hasStyle: () => false }])
+ const wrapperArray = getWrapperArray([
+ { hasStyle: () => true },
+ { hasStyle: () => false }
+ ])
expect(wrapperArray.hasStyle('style', 'value')).to.equal(false)
})
@@ -162,37 +228,58 @@ describeWithShallowAndMount('WrapperArray', (mountingMethod) => {
})
it('is returns false if not every wrapper.is() returns true', () => {
- const wrapperArray = getWrapperArray([{ is: () => true }, { is: () => false }])
+ const wrapperArray = getWrapperArray([
+ { is: () => true },
+ { is: () => false }
+ ])
expect(wrapperArray.is('selector')).to.equal(false)
})
it('isEmpty returns true if every wrapper.isEmpty() returns true', () => {
- const wrapperArray = getWrapperArray([{ isEmpty: () => true }, { isEmpty: () => true }])
+ const wrapperArray = getWrapperArray([
+ { isEmpty: () => true },
+ { isEmpty: () => true }
+ ])
expect(wrapperArray.isEmpty()).to.equal(true)
})
it('isEmpty returns false if not every wrapper.isEmpty() returns true', () => {
- const wrapperArray = getWrapperArray([{ isEmpty: () => true }, { isEmpty: () => false }])
+ const wrapperArray = getWrapperArray([
+ { isEmpty: () => true },
+ { isEmpty: () => false }
+ ])
expect(wrapperArray.isEmpty()).to.equal(false)
})
it('isVisible returns true if every wrapper.isVisible() returns true', () => {
- const wrapperArray = getWrapperArray([{ isVisible: () => true }, { isVisible: () => true }])
+ const wrapperArray = getWrapperArray([
+ { isVisible: () => true },
+ { isVisible: () => true }
+ ])
expect(wrapperArray.isVisible()).to.equal(true)
})
it('isVisible returns false if not every wrapper.isVisible() returns true', () => {
- const wrapperArray = getWrapperArray([{ isVisible: () => true }, { isVisible: () => false }])
+ const wrapperArray = getWrapperArray([
+ { isVisible: () => true },
+ { isVisible: () => false }
+ ])
expect(wrapperArray.isVisible()).to.equal(false)
})
it('isVueInstance returns true if every wrapper.isVueInstance() returns true', () => {
- const wrapperArray = getWrapperArray([{ isVueInstance: () => true }, { isVueInstance: () => true }])
+ const wrapperArray = getWrapperArray([
+ { isVueInstance: () => true },
+ { isVueInstance: () => true }
+ ])
expect(wrapperArray.isVueInstance()).to.equal(true)
})
it('isVueInstance returns false if not every wrapper.isVueInstance() returns true', () => {
- const wrapperArray = getWrapperArray([{ isVueInstance: () => true }, { isVueInstance: () => false }])
+ const wrapperArray = getWrapperArray([
+ { isVueInstance: () => true },
+ { isVueInstance: () => false }
+ ])
expect(wrapperArray.isVueInstance()).to.equal(false)
})
diff --git a/test/specs/wrapper-array/at.spec.js b/test/specs/wrapper-array/at.spec.js
index e9d3b503c..104f66e4d 100644
--- a/test/specs/wrapper-array/at.spec.js
+++ b/test/specs/wrapper-array/at.spec.js
@@ -2,10 +2,12 @@ import { describeWithShallowAndMount } from '~resources/utils'
import { compileToFunctions } from 'vue-template-compiler'
import '~vue/test-utils'
-describeWithShallowAndMount('at', (mountingMethod) => {
+describeWithShallowAndMount('at', mountingMethod => {
it('returns Wrapper at index', () => {
const compiled = compileToFunctions('')
- const p = mountingMethod(compiled).findAll('p').at(1)
+ const p = mountingMethod(compiled)
+ .findAll('p')
+ .at(1)
expect(p.vnode).to.be.an('object')
expect(p.hasClass('index-1')).to.equal(true)
})
@@ -14,6 +16,12 @@ describeWithShallowAndMount('at', (mountingMethod) => {
const index = 2
const compiled = compileToFunctions('')
const message = `[vue-test-utils]: no item exists at ${index}`
- expect(() => mountingMethod(compiled).findAll('p').at(index)).to.throw().with.property('message', message)
+ expect(() =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .at(index)
+ )
+ .to.throw()
+ .with.property('message', message)
})
})
diff --git a/test/specs/wrapper-array/attributes.spec.js b/test/specs/wrapper-array/attributes.spec.js
index 435a5c511..69c8daee5 100644
--- a/test/specs/wrapper-array/attributes.spec.js
+++ b/test/specs/wrapper-array/attributes.spec.js
@@ -2,18 +2,27 @@ import { describeWithShallowAndMount } from '~resources/utils'
import { compileToFunctions } from 'vue-template-compiler'
import '~vue/test-utils'
-describeWithShallowAndMount('attributes', (mountingMethod) => {
+describeWithShallowAndMount('attributes', mountingMethod => {
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('')
const message = '[vue-test-utils]: attributes cannot be called on 0 items'
- expect(() => mountingMethod(compiled).findAll('p').attributes('p')).to.throw().with.property('message', message)
+ expect(() =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .attributes('p')
+ )
+ .to.throw()
+ .with.property('message', message)
})
it('throws error when called on a WrapperArray', () => {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
- const message = '[vue-test-utils]: attributes must be called on a single wrapper, use at(i) to access a wrapper'
+ const message =
+ '[vue-test-utils]: attributes must be called on a single wrapper, use at(i) to access a wrapper'
const fn = () => wrapper.findAll('div').attributes()
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
diff --git a/test/specs/wrapper-array/classes.spec.js b/test/specs/wrapper-array/classes.spec.js
index e92e8a131..5c1d08fd9 100644
--- a/test/specs/wrapper-array/classes.spec.js
+++ b/test/specs/wrapper-array/classes.spec.js
@@ -2,18 +2,27 @@ import { describeWithShallowAndMount } from '~resources/utils'
import { compileToFunctions } from 'vue-template-compiler'
import '~vue/test-utils'
-describeWithShallowAndMount('classes', (mountingMethod) => {
+describeWithShallowAndMount('classes', mountingMethod => {
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('')
const message = '[vue-test-utils]: classes cannot be called on 0 items'
- expect(() => mountingMethod(compiled).findAll('p').classes('p')).to.throw().with.property('message', message)
+ expect(() =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .classes('p')
+ )
+ .to.throw()
+ .with.property('message', message)
})
it('throws error when called on a WrapperArray', () => {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
- const message = '[vue-test-utils]: classes must be called on a single wrapper, use at(i) to access a wrapper'
+ const message =
+ '[vue-test-utils]: classes must be called on a single wrapper, use at(i) to access a wrapper'
const fn = () => wrapper.findAll('div').classes()
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
diff --git a/test/specs/wrapper-array/contains.spec.js b/test/specs/wrapper-array/contains.spec.js
index 14e1a3d61..975aac550 100644
--- a/test/specs/wrapper-array/contains.spec.js
+++ b/test/specs/wrapper-array/contains.spec.js
@@ -2,16 +2,20 @@ import { describeWithShallowAndMount } from '~resources/utils'
import { compileToFunctions } from 'vue-template-compiler'
import '~vue/test-utils'
-describeWithShallowAndMount('contains', (mountingMethod) => {
+describeWithShallowAndMount('contains', mountingMethod => {
it('returns true if every Wrapper contains element', () => {
- const compiled = compileToFunctions('')
+ const compiled = compileToFunctions(
+ ''
+ )
const wrapper = mountingMethod(compiled)
const divArr = wrapper.findAll('div')
expect(divArr.contains('p')).to.equal(true)
})
it('returns false if any Wrapper does not contain element', () => {
- const compiled = compileToFunctions('')
+ const compiled = compileToFunctions(
+ ''
+ )
const wrapper = mountingMethod(compiled)
const divArr = wrapper.findAll('div')
expect(divArr.contains('p')).to.equal(false)
@@ -20,7 +24,13 @@ describeWithShallowAndMount('contains', (mountingMethod) => {
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('')
const message = '[vue-test-utils]: contains cannot be called on 0 items'
- expect(() => mountingMethod(compiled).findAll('p').contains('p')).to.throw().with.property('message', message)
+ expect(() =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .contains('p')
+ )
+ .to.throw()
+ .with.property('message', message)
})
it('throws error if selector is not a valid selector', () => {
@@ -28,11 +38,24 @@ describeWithShallowAndMount('contains', (mountingMethod) => {
const wrapper = mountingMethod(compiled)
const pArr = wrapper.findAll('p')
const invalidSelectors = [
- undefined, null, NaN, 0, 2, true, false, () => {}, {}, { name: undefined }, []
+ undefined,
+ null,
+ NaN,
+ 0,
+ 2,
+ true,
+ false,
+ () => {},
+ {},
+ { name: undefined },
+ []
]
- invalidSelectors.forEach((invalidSelector) => {
- const message = '[vue-test-utils]: wrapper.contains() must be passed a valid CSS selector, Vue constructor, or valid find option object'
- expect(() => pArr.contains(invalidSelector)).to.throw().with.property('message', message)
+ invalidSelectors.forEach(invalidSelector => {
+ const message =
+ '[vue-test-utils]: wrapper.contains() must be passed a valid CSS selector, Vue constructor, or valid find option object'
+ expect(() => pArr.contains(invalidSelector))
+ .to.throw()
+ .with.property('message', message)
})
})
})
diff --git a/test/specs/wrapper-array/find.spec.js b/test/specs/wrapper-array/find.spec.js
index cd4162c17..a7d599e91 100644
--- a/test/specs/wrapper-array/find.spec.js
+++ b/test/specs/wrapper-array/find.spec.js
@@ -2,17 +2,28 @@ import { describeWithShallowAndMount } from '~resources/utils'
import { compileToFunctions } from 'vue-template-compiler'
import '~vue/test-utils'
-describeWithShallowAndMount('find', (mountingMethod) => {
+describeWithShallowAndMount('find', mountingMethod => {
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('')
const message = '[vue-test-utils]: find cannot be called on 0 items'
- expect(() => mountingMethod(compiled).findAll('p').find('p')).to.throw().with.property('message', message)
+ expect(() =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .find('p')
+ )
+ .to.throw()
+ .with.property('message', message)
})
it('throws an error when called on a WrapperArray', () => {
- const compiled = compileToFunctions('')
+ const compiled = compileToFunctions(
+ ''
+ )
const wrapper = mountingMethod(compiled)
- const message = '[vue-test-utils]: find must be called on a single wrapper, use at(i) to access a wrapper'
- expect(() => wrapper.findAll('div').find('div')).to.throw().with.property('message', message)
+ const message =
+ '[vue-test-utils]: find must be called on a single wrapper, use at(i) to access a wrapper'
+ expect(() => wrapper.findAll('div').find('div'))
+ .to.throw()
+ .with.property('message', message)
})
})
diff --git a/test/specs/wrapper-array/findAll.spec.js b/test/specs/wrapper-array/findAll.spec.js
index 4a97e6202..cf4df7c99 100644
--- a/test/specs/wrapper-array/findAll.spec.js
+++ b/test/specs/wrapper-array/findAll.spec.js
@@ -2,17 +2,28 @@ import { describeWithShallowAndMount } from '~resources/utils'
import { compileToFunctions } from 'vue-template-compiler'
import '~vue/test-utils'
-describeWithShallowAndMount('findAll', (mountingMethod) => {
+describeWithShallowAndMount('findAll', mountingMethod => {
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('')
const message = '[vue-test-utils]: findAll cannot be called on 0 items'
- expect(() => mountingMethod(compiled).findAll('p').findAll('p')).to.throw().with.property('message', message)
+ expect(() =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .findAll('p')
+ )
+ .to.throw()
+ .with.property('message', message)
})
it('throws an error when called on a WrapperArray', () => {
- const compiled = compileToFunctions('')
+ const compiled = compileToFunctions(
+ ''
+ )
const wrapper = mountingMethod(compiled)
- const message = '[vue-test-utils]: findAll must be called on a single wrapper, use at(i) to access a wrapper'
- expect(() => wrapper.findAll('div').findAll('div')).to.throw().with.property('message', message)
+ const message =
+ '[vue-test-utils]: findAll must be called on a single wrapper, use at(i) to access a wrapper'
+ expect(() => wrapper.findAll('div').findAll('div'))
+ .to.throw()
+ .with.property('message', message)
})
})
diff --git a/test/specs/wrapper-array/hasAttribute.spec.js b/test/specs/wrapper-array/hasAttribute.spec.js
index a1bf82bb6..1ac0429ce 100644
--- a/test/specs/wrapper-array/hasAttribute.spec.js
+++ b/test/specs/wrapper-array/hasAttribute.spec.js
@@ -2,41 +2,60 @@ import { describeWithShallowAndMount } from '~resources/utils'
import { compileToFunctions } from 'vue-template-compiler'
import '~vue/test-utils'
-describeWithShallowAndMount('hasAttribute', (mountingMethod) => {
+describeWithShallowAndMount('hasAttribute', mountingMethod => {
it('returns true if every item contains attribute matching value', () => {
const attribute = 'attribute'
const value = 'value'
- const compiled = compileToFunctions(``)
+ const compiled = compileToFunctions(
+ ``
+ )
const wrapper = mountingMethod(compiled)
- expect(wrapper.findAll('div').hasAttribute(attribute, value)).to.equal(true)
+ expect(wrapper.findAll('div').hasAttribute(attribute, value)).to.equal(
+ true
+ )
})
it('returns false if every item does not contain attribute', () => {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
- expect(wrapper.findAll('div').hasAttribute('attribute', 'value')).to.equal(false)
+ expect(wrapper.findAll('div').hasAttribute('attribute', 'value')).to.equal(
+ false
+ )
})
it('throws an error if attribute is not a string', () => {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
- const message = '[vue-test-utils]: wrapper.hasAttribute() must be passed attribute as a string'
+ const message =
+ '[vue-test-utils]: wrapper.hasAttribute() must be passed attribute as a string'
const fn = () => wrapper.findAll('div').hasAttribute(undefined, 'value')
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('')
- const message = '[vue-test-utils]: hasAttribute cannot be called on 0 items'
- const fn = () => mountingMethod(compiled).findAll('p').hasAttribute('p')
- expect(fn).to.throw().with.property('message', message)
+ const message =
+ '[vue-test-utils]: hasAttribute cannot be called on 0 items'
+ const fn = () =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .hasAttribute('p')
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
it('throws an error if value is not a string', () => {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
- const message = '[vue-test-utils]: wrapper.hasAttribute() must be passed value as a string'
- const fn = () => wrapper.findAll('div').hasAttribute('attribute', undefined)
- expect(fn).to.throw().with.property('message', message)
+ const message =
+ '[vue-test-utils]: wrapper.hasAttribute() must be passed value as a string'
+ const fn = () =>
+ wrapper.findAll('div').hasAttribute('attribute', undefined)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
diff --git a/test/specs/wrapper-array/hasClass.spec.js b/test/specs/wrapper-array/hasClass.spec.js
index 8a8712564..ebb911986 100644
--- a/test/specs/wrapper-array/hasClass.spec.js
+++ b/test/specs/wrapper-array/hasClass.spec.js
@@ -2,7 +2,7 @@ import { describeWithShallowAndMount } from '~resources/utils'
import { compileToFunctions } from 'vue-template-compiler'
import '~vue/test-utils'
-describeWithShallowAndMount('hasClass', (mountingMethod) => {
+describeWithShallowAndMount('hasClass', mountingMethod => {
it('returns true if every item has class name', () => {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
@@ -18,19 +18,37 @@ describeWithShallowAndMount('hasClass', (mountingMethod) => {
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('')
const message = '[vue-test-utils]: hasClass cannot be called on 0 items'
- expect(() => mountingMethod(compiled).findAll('p').hasClass('p')).to.throw().with.property('message', message)
+ expect(() =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .hasClass('p')
+ )
+ .to.throw()
+ .with.property('message', message)
})
it('throws error if selector is not a string', () => {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
const invalidSelectors = [
- undefined, null, NaN, 0, 2, true, false, () => {}, {}, []
+ undefined,
+ null,
+ NaN,
+ 0,
+ 2,
+ true,
+ false,
+ () => {},
+ {},
+ []
]
- invalidSelectors.forEach((invalidSelector) => {
- const message = '[vue-test-utils]: wrapper.hasClass() must be passed a string'
+ invalidSelectors.forEach(invalidSelector => {
+ const message =
+ '[vue-test-utils]: wrapper.hasClass() must be passed a string'
const fn = () => wrapper.hasClass(invalidSelector)
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
})
diff --git a/test/specs/wrapper-array/hasProp.spec.js b/test/specs/wrapper-array/hasProp.spec.js
index 716355a7c..94daafb23 100644
--- a/test/specs/wrapper-array/hasProp.spec.js
+++ b/test/specs/wrapper-array/hasProp.spec.js
@@ -3,34 +3,60 @@ import ComponentWithChild from '~resources/components/component-with-child.vue'
import Component from '~resources/components/component.vue'
import { describeWithShallowAndMount } from '~resources/utils'
-describeWithShallowAndMount('hasProp', (mountingMethod) => {
+describeWithShallowAndMount('hasProp', mountingMethod => {
it('returns false if every item does not have prop', () => {
const wrapper = mountingMethod(ComponentWithChild)
- expect(wrapper.findAll(Component).hasProp('no-prop', 'value')).to.equal(false)
+ expect(wrapper.findAll(Component).hasProp('no-prop', 'value')).to.equal(
+ false
+ )
})
it('throws error if items are not Vue components', () => {
const compiled = compileToFunctions('')
- const p = mountingMethod(compiled).findAll('p').at(0)
- const message = '[vue-test-utils]: wrapper.hasProp() must be called on a Vue instance'
- expect(() => p.hasProp('no-prop', 'value')).to.throw().with.property('message', message)
+ const p = mountingMethod(compiled)
+ .findAll('p')
+ .at(0)
+ const message =
+ '[vue-test-utils]: wrapper.hasProp() must be called on a Vue instance'
+ expect(() => p.hasProp('no-prop', 'value'))
+ .to.throw()
+ .with.property('message', message)
})
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('')
const message = '[vue-test-utils]: hasProp cannot be called on 0 items'
- expect(() => mountingMethod(compiled).findAll('p').hasProp('p')).to.throw().with.property('message', message)
+ expect(() =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .hasProp('p')
+ )
+ .to.throw()
+ .with.property('message', message)
})
it('throws error if prop is not a string', () => {
const wrapper = mountingMethod(ComponentWithChild)
const invalidSelectors = [
- undefined, null, NaN, 0, 2, true, false, () => {}, {}, []
+ undefined,
+ null,
+ NaN,
+ 0,
+ 2,
+ true,
+ false,
+ () => {},
+ {},
+ []
]
- invalidSelectors.forEach((invalidSelector) => {
- const message = '[vue-test-utils]: wrapper.hasProp() must be passed prop as a string'
- const fn = () => wrapper.find(Component).hasProp(invalidSelector, 'value')
- expect(fn).to.throw().with.property('message', message)
+ invalidSelectors.forEach(invalidSelector => {
+ const message =
+ '[vue-test-utils]: wrapper.hasProp() must be passed prop as a string'
+ const fn = () =>
+ wrapper.find(Component).hasProp(invalidSelector, 'value')
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
})
diff --git a/test/specs/wrapper-array/hasStyle.spec.js b/test/specs/wrapper-array/hasStyle.spec.js
index 52b26f96a..12ec64039 100644
--- a/test/specs/wrapper-array/hasStyle.spec.js
+++ b/test/specs/wrapper-array/hasStyle.spec.js
@@ -2,9 +2,11 @@ import { compileToFunctions } from 'vue-template-compiler'
import ComponentWithStyle from '~resources/components/component-with-style.vue'
import { describeWithShallowAndMount } from '~resources/utils'
-describeWithShallowAndMount('hasStyle', (mountingMethod) => {
+describeWithShallowAndMount('hasStyle', mountingMethod => {
it('returns true if every item contains styles, set inline', () => {
- const compiled = compileToFunctions('')
+ const compiled = compileToFunctions(
+ ''
+ )
const wrapper = mountingMethod(compiled)
expect(wrapper.findAll('div').hasStyle('color', 'red')).to.equal(true)
})
@@ -31,7 +33,9 @@ describeWithShallowAndMount('hasStyle', (mountingMethod) => {
if (navigator.userAgent.includes && navigator.userAgent.includes('jsdom')) {
return
}
- const wrapper = mountingMethod(ComponentWithStyle, { attachToDocument: true })
+ const wrapper = mountingMethod(ComponentWithStyle, {
+ attachToDocument: true
+ })
expect(wrapper.findAll('p').hasStyle('color', 'red')).to.equal(true)
expect(wrapper.findAll('span').hasStyle('color', 'red')).to.equal(true)
expect(wrapper.findAll('span').hasStyle('color', 'orange')).to.equal(false)
@@ -40,23 +44,34 @@ describeWithShallowAndMount('hasStyle', (mountingMethod) => {
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('')
const message = '[vue-test-utils]: hasStyle cannot be called on 0 items'
- const fn = () => mountingMethod(compiled).findAll('p').hasStyle('p')
- expect(fn).to.throw().with.property('message', message)
+ const fn = () =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .hasStyle('p')
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
it('throws error if style is not a string', () => {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
- const message = '[vue-test-utils]: wrapper.hasStyle() must be passed style as a string'
+ const message =
+ '[vue-test-utils]: wrapper.hasStyle() must be passed style as a string'
const fn = () => wrapper.findAll('div').hasStyle(undefined, 'red')
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
it('throws error if value is not a string', () => {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
- const message = '[vue-test-utils]: wrapper.hasClass() must be passed value as string'
+ const message =
+ '[vue-test-utils]: wrapper.hasClass() must be passed value as string'
const fn = () => wrapper.findAll('div').hasStyle('color', undefined)
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
diff --git a/test/specs/wrapper-array/html.spec.js b/test/specs/wrapper-array/html.spec.js
index e35e632ff..f8a24ca53 100644
--- a/test/specs/wrapper-array/html.spec.js
+++ b/test/specs/wrapper-array/html.spec.js
@@ -2,18 +2,27 @@ import { describeWithShallowAndMount } from '~resources/utils'
import { compileToFunctions } from 'vue-template-compiler'
import '~vue/test-utils'
-describeWithShallowAndMount('html', (mountingMethod) => {
+describeWithShallowAndMount('html', mountingMethod => {
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('')
const message = '[vue-test-utils]: html cannot be called on 0 items'
- expect(() => mountingMethod(compiled).findAll('p').html('p')).to.throw().with.property('message', message)
+ expect(() =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .html('p')
+ )
+ .to.throw()
+ .with.property('message', message)
})
it('throws error when called on a WrapperArray', () => {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
- const message = '[vue-test-utils]: html must be called on a single wrapper, use at(i) to access a wrapper'
+ const message =
+ '[vue-test-utils]: html must be called on a single wrapper, use at(i) to access a wrapper'
const fn = () => wrapper.findAll('div').html()
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
diff --git a/test/specs/wrapper-array/is.spec.js b/test/specs/wrapper-array/is.spec.js
index 5ed52c435..87b1bf682 100644
--- a/test/specs/wrapper-array/is.spec.js
+++ b/test/specs/wrapper-array/is.spec.js
@@ -3,7 +3,7 @@ import ComponentWithChild from '~resources/components/component-with-child.vue'
import Component from '~resources/components/component.vue'
import { describeWithShallowAndMount } from '~resources/utils'
-describeWithShallowAndMount('is', (mountingMethod) => {
+describeWithShallowAndMount('is', mountingMethod => {
it('returns true if ech item matches selector', () => {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
@@ -23,7 +23,9 @@ describeWithShallowAndMount('is', (mountingMethod) => {
})
it('returns false if each item does not match tag selector', () => {
- const compiled = compileToFunctions('')
+ const compiled = compileToFunctions(
+ ''
+ )
const wrapper = mountingMethod(compiled)
expect(wrapper.findAll('div').is('.a-class')).to.equal(false)
})
@@ -31,20 +33,38 @@ describeWithShallowAndMount('is', (mountingMethod) => {
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('')
const message = '[vue-test-utils]: is cannot be called on 0 items'
- const fn = () => mountingMethod(compiled).findAll('p').is('p')
- expect(fn).to.throw().with.property('message', message)
+ const fn = () =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .is('p')
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
it('throws error if selector is not a valid selector', () => {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
const invalidSelectors = [
- undefined, null, NaN, 0, 2, true, false, () => {}, {}, { name: undefined }, []
+ undefined,
+ null,
+ NaN,
+ 0,
+ 2,
+ true,
+ false,
+ () => {},
+ {},
+ { name: undefined },
+ []
]
- invalidSelectors.forEach((invalidSelector) => {
- const message = '[vue-test-utils]: wrapper.is() must be passed a valid CSS selector, Vue constructor, or valid find option object'
+ invalidSelectors.forEach(invalidSelector => {
+ const message =
+ '[vue-test-utils]: wrapper.is() must be passed a valid CSS selector, Vue constructor, or valid find option object'
const fn = () => wrapper.findAll('div').is(invalidSelector)
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
})
diff --git a/test/specs/wrapper-array/isEmpty.spec.js b/test/specs/wrapper-array/isEmpty.spec.js
index 222b3df36..4a024482c 100644
--- a/test/specs/wrapper-array/isEmpty.spec.js
+++ b/test/specs/wrapper-array/isEmpty.spec.js
@@ -2,7 +2,7 @@ import { describeWithShallowAndMount } from '~resources/utils'
import { compileToFunctions } from 'vue-template-compiler'
import '~vue/test-utils'
-describeWithShallowAndMount('isEmpty', (mountingMethod) => {
+describeWithShallowAndMount('isEmpty', mountingMethod => {
it('returns true if node is empty', () => {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
@@ -20,7 +20,12 @@ describeWithShallowAndMount('isEmpty', (mountingMethod) => {
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('')
const message = '[vue-test-utils]: isEmpty cannot be called on 0 items'
- const fn = () => mountingMethod(compiled).findAll('p').isEmpty('p')
- expect(fn).to.throw().with.property('message', message)
+ const fn = () =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .isEmpty('p')
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
diff --git a/test/specs/wrapper-array/isVisible.spec.js b/test/specs/wrapper-array/isVisible.spec.js
index c8bbc7ada..1063ee658 100644
--- a/test/specs/wrapper-array/isVisible.spec.js
+++ b/test/specs/wrapper-array/isVisible.spec.js
@@ -2,7 +2,7 @@ import { describeWithShallowAndMount } from '~resources/utils'
import { compileToFunctions } from 'vue-template-compiler'
import '~vue/test-utils'
-describeWithShallowAndMount('isVisible', (mountingMethod) => {
+describeWithShallowAndMount('isVisible', mountingMethod => {
it('returns true if node has no inline style', () => {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
@@ -11,14 +11,18 @@ describeWithShallowAndMount('isVisible', (mountingMethod) => {
})
it('returns false if node has inline style display: none', () => {
- const compiled = compileToFunctions('')
+ const compiled = compileToFunctions(
+ ''
+ )
const wrapper = mountingMethod(compiled)
expect(wrapper.findAll('p').isVisible()).to.equal(false)
})
it('returns false if node has visibility: hidden', () => {
- const compiled = compileToFunctions('')
+ const compiled = compileToFunctions(
+ ''
+ )
const wrapper = mountingMethod(compiled)
expect(wrapper.findAll('p').isVisible()).to.equal(false)
@@ -27,7 +31,12 @@ describeWithShallowAndMount('isVisible', (mountingMethod) => {
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('')
const message = '[vue-test-utils]: isVisible cannot be called on 0 items'
- const fn = () => mountingMethod(compiled).findAll('p').isVisible('p')
- expect(fn).to.throw().with.property('message', message)
+ const fn = () =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .isVisible('p')
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
diff --git a/test/specs/wrapper-array/isVueInstance.spec.js b/test/specs/wrapper-array/isVueInstance.spec.js
index 11f1c8159..96c84d335 100644
--- a/test/specs/wrapper-array/isVueInstance.spec.js
+++ b/test/specs/wrapper-array/isVueInstance.spec.js
@@ -3,7 +3,7 @@ import ComponentWithChild from '~resources/components/component-with-child.vue'
import Component from '~resources/components/component.vue'
import { describeWithShallowAndMount } from '~resources/utils'
-describeWithShallowAndMount('isVueInstance', (mountingMethod) => {
+describeWithShallowAndMount('isVueInstance', mountingMethod => {
it('returns true if wrapper is Vue instance', () => {
const wrapper = mountingMethod(ComponentWithChild)
expect(wrapper.findAll(Component).isVueInstance()).to.equal(true)
@@ -17,8 +17,14 @@ describeWithShallowAndMount('isVueInstance', (mountingMethod) => {
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('')
- const message = '[vue-test-utils]: isVueInstance cannot be called on 0 items'
- const fn = () => mountingMethod(compiled).findAll('p').isVueInstance('p')
- expect(fn).to.throw().with.property('message', message)
+ const message =
+ '[vue-test-utils]: isVueInstance cannot be called on 0 items'
+ const fn = () =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .isVueInstance('p')
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
diff --git a/test/specs/wrapper-array/name.spec.js b/test/specs/wrapper-array/name.spec.js
index 76b30bff1..50e33c4b2 100644
--- a/test/specs/wrapper-array/name.spec.js
+++ b/test/specs/wrapper-array/name.spec.js
@@ -2,18 +2,26 @@ import { describeWithShallowAndMount } from '~resources/utils'
import { compileToFunctions } from 'vue-template-compiler'
import '~vue/test-utils'
-describeWithShallowAndMount('name', (mountingMethod) => {
+describeWithShallowAndMount('name', mountingMethod => {
it('throws an error when called on a WrapperArray', () => {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
- const message = '[vue-test-utils]: name must be called on a single wrapper, use at(i) to access a wrapper'
- expect(() => wrapper.findAll('div').name()).to.throw().with.property('message', message)
+ const message =
+ '[vue-test-utils]: name must be called on a single wrapper, use at(i) to access a wrapper'
+ expect(() => wrapper.findAll('div').name())
+ .to.throw()
+ .with.property('message', message)
})
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('')
const message = '[vue-test-utils]: name cannot be called on 0 items'
- const fn = () => mountingMethod(compiled).findAll('p').name('p')
- expect(fn).to.throw().with.property('message', message)
+ const fn = () =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .name('p')
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
diff --git a/test/specs/wrapper-array/props.spec.js b/test/specs/wrapper-array/props.spec.js
index e4ac79261..f7cb3956f 100644
--- a/test/specs/wrapper-array/props.spec.js
+++ b/test/specs/wrapper-array/props.spec.js
@@ -2,18 +2,27 @@ import { describeWithShallowAndMount } from '~resources/utils'
import { compileToFunctions } from 'vue-template-compiler'
import '~vue/test-utils'
-describeWithShallowAndMount('props', (mountingMethod) => {
+describeWithShallowAndMount('props', mountingMethod => {
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('')
const message = '[vue-test-utils]: props cannot be called on 0 items'
- expect(() => mountingMethod(compiled).findAll('p').props('p')).to.throw().with.property('message', message)
+ expect(() =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .props('p')
+ )
+ .to.throw()
+ .with.property('message', message)
})
it('throws error when called on a WrapperArray', () => {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
- const message = '[vue-test-utils]: props must be called on a single wrapper, use at(i) to access a wrapper'
+ const message =
+ '[vue-test-utils]: props must be called on a single wrapper, use at(i) to access a wrapper'
const fn = () => wrapper.findAll('div').props()
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
diff --git a/test/specs/wrapper-array/setData.spec.js b/test/specs/wrapper-array/setData.spec.js
index fffd8dfbf..b0635da19 100644
--- a/test/specs/wrapper-array/setData.spec.js
+++ b/test/specs/wrapper-array/setData.spec.js
@@ -2,7 +2,7 @@ import { compileToFunctions } from 'vue-template-compiler'
import ComponentWithVIf from '~resources/components/component-with-v-if.vue'
import { describeWithShallowAndMount } from '~resources/utils'
-describeWithShallowAndMount('setData', (mountingMethod) => {
+describeWithShallowAndMount('setData', mountingMethod => {
it('sets component data and updates nested vm nodes when called on Vue instance', () => {
const TestComponent = {
render: h => h(ComponentWithVIf)
@@ -15,17 +15,25 @@ describeWithShallowAndMount('setData', (mountingMethod) => {
})
it('throws an error if node is not a Vue instance', () => {
- const message = '[vue-test-utils]: wrapper.setData() can only be called on a Vue instance'
+ const message =
+ '[vue-test-utils]: wrapper.setData() can only be called on a Vue instance'
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
const fn = () => wrapper.findAll('p').setData({ ready: true })
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('')
const message = '[vue-test-utils]: setData cannot be called on 0 items'
- const fn = () => mountingMethod(compiled).findAll('p').setData('p')
- expect(fn).to.throw().with.property('message', message)
+ const fn = () =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .setData('p')
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
diff --git a/test/specs/wrapper-array/setProps.spec.js b/test/specs/wrapper-array/setProps.spec.js
index 09fa5ccfd..0909d7a0e 100644
--- a/test/specs/wrapper-array/setProps.spec.js
+++ b/test/specs/wrapper-array/setProps.spec.js
@@ -2,7 +2,7 @@ import { compileToFunctions } from 'vue-template-compiler'
import ComponentWithProps from '~resources/components/component-with-props.vue'
import { describeWithShallowAndMount } from '~resources/utils'
-describeWithShallowAndMount('setProps', (mountingMethod) => {
+describeWithShallowAndMount('setProps', mountingMethod => {
it('sets component props and updates DOM when called on Vue instance', () => {
const prop1 = 'prop 1'
const prop2 = 'prop 2'
@@ -29,18 +29,26 @@ describeWithShallowAndMount('setProps', (mountingMethod) => {
})
it('throws an error if node is not a Vue instance', () => {
- const message = '[vue-test-utils]: wrapper.setProps() can only be called on a Vue instance'
+ const message =
+ '[vue-test-utils]: wrapper.setProps() can only be called on a Vue instance'
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
const p = wrapper.findAll('p')
const fn = () => p.setProps({ ready: true })
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('')
const message = '[vue-test-utils]: setProps cannot be called on 0 items'
- const fn = () => mountingMethod(compiled).findAll('p').setProps('p')
- expect(fn).to.throw().with.property('message', message)
+ const fn = () =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .setProps('p')
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
diff --git a/test/specs/wrapper-array/text.spec.js b/test/specs/wrapper-array/text.spec.js
index ba7cb0e06..15b1a553b 100644
--- a/test/specs/wrapper-array/text.spec.js
+++ b/test/specs/wrapper-array/text.spec.js
@@ -2,19 +2,27 @@ import { describeWithShallowAndMount } from '~resources/utils'
import { compileToFunctions } from 'vue-template-compiler'
import '~vue/test-utils'
-describeWithShallowAndMount('text', (mountingMethod) => {
+describeWithShallowAndMount('text', mountingMethod => {
it('throws error when called on a WrapperArray', () => {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
- const message = '[vue-test-utils]: text must be called on a single wrapper, use at(i) to access a wrapper'
+ const message =
+ '[vue-test-utils]: text must be called on a single wrapper, use at(i) to access a wrapper'
const fn = () => wrapper.findAll('div').text()
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('')
const message = '[vue-test-utils]: text cannot be called on 0 items'
- const fn = () => mountingMethod(compiled).findAll('p').text('p')
- expect(fn).to.throw().with.property('message', message)
+ const fn = () =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .text('p')
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
diff --git a/test/specs/wrapper-array/trigger.spec.js b/test/specs/wrapper-array/trigger.spec.js
index a20865372..cc27da5cc 100644
--- a/test/specs/wrapper-array/trigger.spec.js
+++ b/test/specs/wrapper-array/trigger.spec.js
@@ -2,7 +2,7 @@ import { compileToFunctions } from 'vue-template-compiler'
import ComponentWithEvents from '~resources/components/component-with-events.vue'
import { describeWithShallowAndMount } from '~resources/utils'
-describeWithShallowAndMount('trigger', (mountingMethod) => {
+describeWithShallowAndMount('trigger', mountingMethod => {
it('causes click handler to fire when wrapper.trigger("click") is called on a Component', () => {
const clickHandler = sinon.stub()
const wrapper = mountingMethod(ComponentWithEvents, {
@@ -45,19 +45,36 @@ describeWithShallowAndMount('trigger', (mountingMethod) => {
it('throws an error if type is not a string', () => {
const wrapper = mountingMethod(ComponentWithEvents)
const invalidSelectors = [
- undefined, null, NaN, 0, 2, true, false, () => {}, {}, []
+ undefined,
+ null,
+ NaN,
+ 0,
+ 2,
+ true,
+ false,
+ () => {},
+ {},
+ []
]
- invalidSelectors.forEach((invalidSelector) => {
- const message = '[vue-test-utils]: wrapper.trigger() must be passed a string'
+ invalidSelectors.forEach(invalidSelector => {
+ const message =
+ '[vue-test-utils]: wrapper.trigger() must be passed a string'
const fn = () => wrapper.trigger(invalidSelector)
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('')
const message = '[vue-test-utils]: trigger cannot be called on 0 items'
- const fn = () => mountingMethod(compiled).findAll('p').trigger('p')
- expect(fn).to.throw().with.property('message', message)
+ const fn = () =>
+ mountingMethod(compiled)
+ .findAll('p')
+ .trigger('p')
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
diff --git a/test/specs/wrapper/at.spec.js b/test/specs/wrapper/at.spec.js
index ade02cb24..005174445 100644
--- a/test/specs/wrapper/at.spec.js
+++ b/test/specs/wrapper/at.spec.js
@@ -1,12 +1,14 @@
import { compileToFunctions } from 'vue-template-compiler'
import { describeWithShallowAndMount } from '~resources/utils'
-describeWithShallowAndMount('at', (mountingMethod) => {
+describeWithShallowAndMount('at', mountingMethod => {
it('throws an error', () => {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
const message = '[vue-test-utils]: at() must be called on a WrapperArray'
const fn = () => wrapper.at()
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
diff --git a/test/specs/wrapper/attributes.spec.js b/test/specs/wrapper/attributes.spec.js
index 08b9cbc13..e93b91bfb 100644
--- a/test/specs/wrapper/attributes.spec.js
+++ b/test/specs/wrapper/attributes.spec.js
@@ -1,7 +1,7 @@
import { compileToFunctions } from 'vue-template-compiler'
import { describeWithShallowAndMount } from '~resources/utils'
-describeWithShallowAndMount('attributes', (mountingMethod) => {
+describeWithShallowAndMount('attributes', mountingMethod => {
it('returns true if wrapper contains attribute matching value', () => {
const attribute = 'attribute'
const value = 'value'
diff --git a/test/specs/wrapper/classes.spec.js b/test/specs/wrapper/classes.spec.js
index 3dc6738be..d70bd6ae4 100644
--- a/test/specs/wrapper/classes.spec.js
+++ b/test/specs/wrapper/classes.spec.js
@@ -2,7 +2,7 @@ import { describeWithShallowAndMount } from '~resources/utils'
import { compileToFunctions } from 'vue-template-compiler'
import ComponentWithCssModules from '~resources/components/component-with-css-modules.vue'
-describeWithShallowAndMount('classes', (mountingMethod) => {
+describeWithShallowAndMount('classes', mountingMethod => {
it('returns array of class names if wrapper has class names', () => {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
@@ -22,7 +22,9 @@ describeWithShallowAndMount('classes', (mountingMethod) => {
})
it('returns array of class names for svg element', () => {
- const compiled = compileToFunctions('')
+ const compiled = compileToFunctions(
+ ''
+ )
const wrapper = mountingMethod(compiled)
expect(wrapper.classes()).to.contain('a-class')
expect(wrapper.classes()).to.contain('b-class')
diff --git a/test/specs/wrapper/contains.spec.js b/test/specs/wrapper/contains.spec.js
index 1abb600b3..fc04a7707 100644
--- a/test/specs/wrapper/contains.spec.js
+++ b/test/specs/wrapper/contains.spec.js
@@ -11,7 +11,7 @@ import {
import { itSkipIf } from 'conditional-specs'
import ComponentWithoutName from '~resources/components/component-without-name.vue'
-describeWithShallowAndMount('contains', (mountingMethod) => {
+describeWithShallowAndMount('contains', mountingMethod => {
it('returns true if wrapper contains element', () => {
const compiled = compileToFunctions('')
const wrapper = mountingMethod(compiled)
@@ -44,7 +44,8 @@ describeWithShallowAndMount('contains', (mountingMethod) => {
itSkipIf(
isRunningPhantomJS,
- 'returns true if wrapper contains Vue class component', () => {
+ 'returns true if wrapper contains Vue class component',
+ () => {
const TestComponent = {
template: `
@@ -57,7 +58,8 @@ describeWithShallowAndMount('contains', (mountingMethod) => {
}
const wrapper = mountingMethod(TestComponent)
expect(wrapper.contains(ComponentAsAClass)).to.equal(true)
- })
+ }
+ )
it('returns true if wrapper contains element specified by ref selector', () => {
const compiled = compileToFunctions('
')
@@ -69,9 +71,12 @@ describeWithShallowAndMount('contains', (mountingMethod) => {
const compiled = compileToFunctions('
')
const wrapper = mountingMethod(compiled)
const a = wrapper.find('a')
- const message = '[vue-test-utils]: $ref selectors can only be used on Vue component wrappers'
+ const message =
+ '[vue-test-utils]: $ref selectors can only be used on Vue component wrappers'
const fn = () => a.contains({ ref: 'foo' })
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
it('returns true when wrapper contains root element', () => {
@@ -136,12 +141,26 @@ describeWithShallowAndMount('contains', (mountingMethod) => {
it('throws an error if selector is not a valid selector', () => {
const wrapper = mountingMethod(Component)
const invalidSelectors = [
- undefined, null, NaN, 0, 2, true, false, () => {}, {}, { name: undefined }, { ref: 'foo', nope: true }, []
+ undefined,
+ null,
+ NaN,
+ 0,
+ 2,
+ true,
+ false,
+ () => {},
+ {},
+ { name: undefined },
+ { ref: 'foo', nope: true },
+ []
]
- invalidSelectors.forEach((invalidSelector) => {
- const message = '[vue-test-utils]: wrapper.contains() must be passed a valid CSS selector, Vue constructor, or valid find option object'
+ invalidSelectors.forEach(invalidSelector => {
+ const message =
+ '[vue-test-utils]: wrapper.contains() must be passed a valid CSS selector, Vue constructor, or valid find option object'
const fn = () => wrapper.contains(invalidSelector)
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
})
diff --git a/test/specs/wrapper/destroy.spec.js b/test/specs/wrapper/destroy.spec.js
index a66e7721b..4fe466a34 100644
--- a/test/specs/wrapper/destroy.spec.js
+++ b/test/specs/wrapper/destroy.spec.js
@@ -2,7 +2,7 @@ import { compileToFunctions } from 'vue-template-compiler'
import { describeWithShallowAndMount } from '~resources/utils'
import sinon from 'sinon'
-describeWithShallowAndMount('destroy', (mountingMethod) => {
+describeWithShallowAndMount('destroy', mountingMethod => {
it('triggers beforeDestroy ', () => {
const spy = sinon.stub()
mountingMethod({
diff --git a/test/specs/wrapper/emitted.spec.js b/test/specs/wrapper/emitted.spec.js
index da0a98930..d337dfdaa 100644
--- a/test/specs/wrapper/emitted.spec.js
+++ b/test/specs/wrapper/emitted.spec.js
@@ -1,7 +1,7 @@
import { createLocalVue } from '~vue/test-utils'
import { describeWithShallowAndMount } from '~resources/utils'
-describeWithShallowAndMount('emitted', (mountingMethod) => {
+describeWithShallowAndMount('emitted', mountingMethod => {
it('captures emitted events with a different api', () => {
const wrapper = mountingMethod({
render: h => h('div')
@@ -50,10 +50,13 @@ describeWithShallowAndMount('emitted', (mountingMethod) => {
const wrapper = mountingMethod({
template: '
'
})
- const message = '[vue-test-utils]: wrapper.emitted() can only be called on a Vue instance'
+ const message =
+ '[vue-test-utils]: wrapper.emitted() can only be called on a Vue instance'
const fn = () => wrapper.find('p').emitted()
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
it('captures all events thrown after beforeCreate lifecycle hook', () => {
@@ -74,19 +77,25 @@ describeWithShallowAndMount('emitted', (mountingMethod) => {
it('captures only events from its component without side effects on localVue', () => {
const localVue = createLocalVue()
- const wrapper1 = mountingMethod({
- render: () => {},
- beforeCreate () {
- this.$emit('foo')
- }
- }, { localVue })
-
- const wrapper2 = mountingMethod({
- render: () => {},
- mounted () {
- this.$emit('bar')
- }
- }, { localVue })
+ const wrapper1 = mountingMethod(
+ {
+ render: () => {},
+ beforeCreate () {
+ this.$emit('foo')
+ }
+ },
+ { localVue }
+ )
+
+ const wrapper2 = mountingMethod(
+ {
+ render: () => {},
+ mounted () {
+ this.$emit('bar')
+ }
+ },
+ { localVue }
+ )
expect(wrapper1.emitted().foo).to.eql([[]])
expect(wrapper1.emitted().bar).to.eql(undefined)
diff --git a/test/specs/wrapper/emittedByOrder.spec.js b/test/specs/wrapper/emittedByOrder.spec.js
index 2364a5a28..5c548395c 100644
--- a/test/specs/wrapper/emittedByOrder.spec.js
+++ b/test/specs/wrapper/emittedByOrder.spec.js
@@ -1,7 +1,7 @@
import Vue from 'vue'
import { describeWithShallowAndMount } from '~resources/utils'
-describeWithShallowAndMount('emittedByOrder', (mountingMethod) => {
+describeWithShallowAndMount('emittedByOrder', mountingMethod => {
it('captures emitted events in order', () => {
const wrapper = mountingMethod({
render: h => h('div')
@@ -34,10 +34,13 @@ describeWithShallowAndMount('emittedByOrder', (mountingMethod) => {
const wrapper = mountingMethod({
template: '
'
})
- const message = '[vue-test-utils]: wrapper.emittedByOrder() can only be called on a Vue instance'
+ const message =
+ '[vue-test-utils]: wrapper.emittedByOrder() can only be called on a Vue instance'
const fn = () => wrapper.find('p').emittedByOrder()
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
it('captures in lifecycle hooks emitted events in order', () => {
diff --git a/test/specs/wrapper/exists.spec.js b/test/specs/wrapper/exists.spec.js
index f912d6b7b..8fd2b63d3 100644
--- a/test/specs/wrapper/exists.spec.js
+++ b/test/specs/wrapper/exists.spec.js
@@ -1,7 +1,7 @@
import { compileToFunctions } from 'vue-template-compiler'
import { describeWithShallowAndMount } from '~resources/utils'
-describeWithShallowAndMount('exists', (mountingMethod) => {
+describeWithShallowAndMount('exists', mountingMethod => {
it('returns true if called on Wrapper', () => {
const compiled = compileToFunctions('
')
const wrapper = mountingMethod(compiled)
diff --git a/test/specs/wrapper/filter.spec.js b/test/specs/wrapper/filter.spec.js
index ac08fc391..876fe5582 100644
--- a/test/specs/wrapper/filter.spec.js
+++ b/test/specs/wrapper/filter.spec.js
@@ -1,12 +1,15 @@
import { compileToFunctions } from 'vue-template-compiler'
import { describeWithShallowAndMount } from '~resources/utils'
-describeWithShallowAndMount('filter', (mountingMethod) => {
+describeWithShallowAndMount('filter', mountingMethod => {
it('throws an error', () => {
const compiled = compileToFunctions('
')
const wrapper = mountingMethod(compiled)
- const message = '[vue-test-utils]: filter() must be called on a WrapperArray'
+ const message =
+ '[vue-test-utils]: filter() must be called on a WrapperArray'
const fn = () => wrapper.filter()
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
diff --git a/test/specs/wrapper/find.spec.js b/test/specs/wrapper/find.spec.js
index bf5e7ea22..fb7677f66 100644
--- a/test/specs/wrapper/find.spec.js
+++ b/test/specs/wrapper/find.spec.js
@@ -13,12 +13,9 @@ import {
describeWithShallowAndMount,
isRunningPhantomJS
} from '~resources/utils'
-import {
- itDoNotRunIf,
- itSkipIf
-} from 'conditional-specs'
+import { itDoNotRunIf, itSkipIf } from 'conditional-specs'
-describeWithShallowAndMount('find', (mountingMethod) => {
+describeWithShallowAndMount('find', mountingMethod => {
it('returns a Wrapper matching tag selector passed', () => {
const compiled = compileToFunctions('
')
const wrapper = mountingMethod(compiled)
@@ -39,14 +36,16 @@ describeWithShallowAndMount('find', (mountingMethod) => {
itDoNotRunIf(
isRunningPhantomJS,
- 'returns an array of Wrapper of elements matching class selector passed if they are declared inside a slot', () => {
+ 'returns an array of Wrapper of elements matching class selector passed if they are declared inside a slot',
+ () => {
const wrapper = mountingMethod(ComponentWithSlots, {
slots: {
default: '
'
}
})
expect(wrapper.find('.foo').vnode).to.be.an('object')
- })
+ }
+ )
it('returns Wrapper matching class selector passed if they are declared inside a functional component', () => {
const Component = {
@@ -54,7 +53,7 @@ describeWithShallowAndMount('find', (mountingMethod) => {
render (h, { props }) {
return h('div', {}, [
h('p', {
- 'class': {
+ class: {
foo: true
}
}),
@@ -87,13 +86,18 @@ describeWithShallowAndMount('find', (mountingMethod) => {
it('throws an error when passed an invalid DOM selector', () => {
const compiled = compileToFunctions('
')
const wrapper = mountingMethod(compiled)
- const message = '[vue-test-utils]: wrapper.find() must be passed a valid CSS selector, Vue constructor, or valid find option object'
+ const message =
+ '[vue-test-utils]: wrapper.find() must be passed a valid CSS selector, Vue constructor, or valid find option object'
const fn = () => wrapper.find('[href=&6"/"]')
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
it('returns Wrapper of elements matching selector when descendant combinator passed', () => {
- const compiled = compileToFunctions('
')
+ const compiled = compileToFunctions(
+ '
'
+ )
const wrapper = mountingMethod(compiled)
expect(wrapper.find('div li').vnode).to.be.an('object')
})
@@ -115,23 +119,21 @@ describeWithShallowAndMount('find', (mountingMethod) => {
expect(wrapper.find(Component).vnode).to.be.an('object')
})
- itSkipIf(
- isRunningPhantomJS,
- 'returns Wrapper of class component', () => {
- const TestComponent = {
- template: `
+ itSkipIf(isRunningPhantomJS, 'returns Wrapper of class component', () => {
+ const TestComponent = {
+ template: `
`,
- components: {
- ComponentAsAClass
- }
+ components: {
+ ComponentAsAClass
}
+ }
- const wrapper = mountingMethod(TestComponent)
- expect(wrapper.find(ComponentAsAClass).vnode).to.be.an('object')
- })
+ const wrapper = mountingMethod(TestComponent)
+ expect(wrapper.find(ComponentAsAClass).vnode).to.be.an('object')
+ })
it('returns Wrapper of Vue Component matching functional component', () => {
if (!functionalSFCsSupported) {
@@ -167,9 +169,12 @@ describeWithShallowAndMount('find', (mountingMethod) => {
}
const wrapper = mountingMethod(TestComponent)
if (vueVersion < 2.3) {
- const message = '[vue-test-utils]: find for functional components is not support in Vue < 2.3'
+ const message =
+ '[vue-test-utils]: find for functional components is not support in Vue < 2.3'
const fn = () => wrapper.find(TestFunctionalComponent)
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
} else {
expect(wrapper.find(TestFunctionalComponent).exists()).to.equal(true)
}
@@ -186,7 +191,12 @@ describeWithShallowAndMount('find', (mountingMethod) => {
}
}
const wrapper = mountingMethod(TestComponent)
- expect(wrapper.find('svg').find('svg').exists()).to.equal(true)
+ expect(
+ wrapper
+ .find('svg')
+ .find('svg')
+ .exists()
+ ).to.equal(true)
})
it('throws errror when searching for a component on an element Wrapper', () => {
@@ -199,9 +209,15 @@ describeWithShallowAndMount('find', (mountingMethod) => {
})
}
}
- const fn = () => mountingMethod(TestComponent).find('svg').find(Component)
- const message = '[vue-test-utils]: cannot find a Vue instance on a DOM node. The node you are calling find on does not exist in the VDom. Are you adding the node as innerHTML?'
- expect(fn).to.throw().with.property('message', message)
+ const fn = () =>
+ mountingMethod(TestComponent)
+ .find('svg')
+ .find(Component)
+ const message =
+ '[vue-test-utils]: cannot find a Vue instance on a DOM node. The node you are calling find on does not exist in the VDom. Are you adding the node as innerHTML?'
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
it('throws errror when using ref selector on an element Wrapper', () => {
@@ -214,9 +230,15 @@ describeWithShallowAndMount('find', (mountingMethod) => {
})
}
}
- const fn = () => mountingMethod(TestComponent).find('svg').find({ ref: 'some-ref' })
- const message = '[vue-test-utils]: cannot find a Vue instance on a DOM node. The node you are calling find on does not exist in the VDom. Are you adding the node as innerHTML?'
- expect(fn).to.throw().with.property('message', message)
+ const fn = () =>
+ mountingMethod(TestComponent)
+ .find('svg')
+ .find({ ref: 'some-ref' })
+ const message =
+ '[vue-test-utils]: cannot find a Vue instance on a DOM node. The node you are calling find on does not exist in the VDom. Are you adding the node as innerHTML?'
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
it('returns correct number of Vue Wrappers when component has a v-for', () => {
@@ -296,7 +318,9 @@ describeWithShallowAndMount('find', (mountingMethod) => {
it('returns a Wrapper matching a component name in options object', () => {
const wrapper = mountingMethod(ComponentWithChild)
- expect(wrapper.find({ name: 'test-component' }).name()).to.equal('test-component')
+ expect(wrapper.find({ name: 'test-component' }).name()).to.equal(
+ 'test-component'
+ )
})
it('returns Wrapper of Vue Component matching the ref in options object', () => {
@@ -308,13 +332,18 @@ describeWithShallowAndMount('find', (mountingMethod) => {
const compiled = compileToFunctions('
')
const wrapper = mountingMethod(compiled)
const a = wrapper.find('a')
- const message = '[vue-test-utils]: $ref selectors can only be used on Vue component wrappers'
+ const message =
+ '[vue-test-utils]: $ref selectors can only be used on Vue component wrappers'
const fn = () => a.find({ ref: 'foo' })
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
it('returns Wrapper matching ref selector in options object passed if nested in a transition', () => {
- const compiled = compileToFunctions('
')
+ const compiled = compileToFunctions(
+ '
'
+ )
const wrapper = mountingMethod(compiled)
expect(wrapper.find({ ref: 'foo' })).to.be.an('object')
})
@@ -344,12 +373,26 @@ describeWithShallowAndMount('find', (mountingMethod) => {
it('throws an error if selector is not a valid selector', () => {
const wrapper = mountingMethod(Component)
const invalidSelectors = [
- undefined, null, NaN, 0, 2, true, false, () => {}, {}, { name: undefined }, { ref: 'foo', nope: true }, []
+ undefined,
+ null,
+ NaN,
+ 0,
+ 2,
+ true,
+ false,
+ () => {},
+ {},
+ { name: undefined },
+ { ref: 'foo', nope: true },
+ []
]
- invalidSelectors.forEach((invalidSelector) => {
- const message = '[vue-test-utils]: wrapper.find() must be passed a valid CSS selector, Vue constructor, or valid find option object'
+ invalidSelectors.forEach(invalidSelector => {
+ const message =
+ '[vue-test-utils]: wrapper.find() must be passed a valid CSS selector, Vue constructor, or valid find option object'
const fn = () => wrapper.find(invalidSelector)
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
})
})
diff --git a/test/specs/wrapper/findAll.spec.js b/test/specs/wrapper/findAll.spec.js
index 115ea9941..7908fe6df 100644
--- a/test/specs/wrapper/findAll.spec.js
+++ b/test/specs/wrapper/findAll.spec.js
@@ -11,12 +11,9 @@ import {
describeWithShallowAndMount,
isRunningPhantomJS
} from '~resources/utils'
-import {
- itDoNotRunIf,
- itSkipIf
-} from 'conditional-specs'
+import { itDoNotRunIf, itSkipIf } from 'conditional-specs'
-describeWithShallowAndMount('findAll', (mountingMethod) => {
+describeWithShallowAndMount('findAll', mountingMethod => {
it('returns an WrapperArray of elements matching tag selector passed', () => {
const compiled = compileToFunctions('
')
const wrapper = mountingMethod(compiled)
@@ -40,7 +37,8 @@ describeWithShallowAndMount('findAll', (mountingMethod) => {
itDoNotRunIf(
isRunningPhantomJS,
- 'returns an array of Wrapper of elements matching class selector passed if they are declared inside a slot', () => {
+ 'returns an array of Wrapper of elements matching class selector passed if they are declared inside a slot',
+ () => {
const wrapper = mountingMethod(ComponentWithSlots, {
slots: {
default: '
'
@@ -48,7 +46,8 @@ describeWithShallowAndMount('findAll', (mountingMethod) => {
})
const fooArr = wrapper.findAll('.foo')
expect(fooArr.length).to.equal(2)
- })
+ }
+ )
it('returns an array of Wrapper of elements matching class selector passed if they are declared inside a functional component', () => {
const Component = {
@@ -56,7 +55,7 @@ describeWithShallowAndMount('findAll', (mountingMethod) => {
render (h) {
return h('p', {}, [
h('p', {
- 'class': {
+ class: {
foo: true
}
}),
@@ -101,20 +100,27 @@ describeWithShallowAndMount('findAll', (mountingMethod) => {
it('throws an error when passed an invalid DOM selector', () => {
const compiled = compileToFunctions('
')
const wrapper = mountingMethod(compiled)
- const message = '[vue-test-utils]: wrapper.findAll() must be passed a valid CSS selector, Vue constructor, or valid find option object'
+ const message =
+ '[vue-test-utils]: wrapper.findAll() must be passed a valid CSS selector, Vue constructor, or valid find option object'
const fn = () => wrapper.findAll('[href=&6"/"]')
- expect(fn).to.throw().with.property('message', message)
+ expect(fn)
+ .to.throw()
+ .with.property('message', message)
})
it('returns an array of Wrappers of elements matching selector when descendant combinator passed', () => {
- const compiled = compileToFunctions('
')
+ const compiled = compileToFunctions(
+ '
'
+ )
const wrapper = mountingMethod(compiled)
const liArr = wrapper.findAll('div li')
expect(liArr.length).to.equal(2)
})
it('does not return duplicate nodes', () => {
- const compiled = compileToFunctions('
')
+ const compiled = compileToFunctions(
+ '