Skip to content

Commit a251762

Browse files
38elementseddyerburgh
authored andcommitted
test: refactor test/unit/specs/wrappers/error-wrapper.spec.js (#303)
1 parent 6cb1711 commit a251762

File tree

1 file changed

+15
-181
lines changed

1 file changed

+15
-181
lines changed
Lines changed: 15 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -1,185 +1,19 @@
1-
import ErrorWrapper from '../../../../src/wrappers/error-wrapper'
1+
import { mount } from '~vue-test-utils'
2+
import { compileToFunctions } from 'vue-template-compiler'
23

34
describe('ErrorWrapper', () => {
4-
it('at throws error when called', () => {
5-
const selector = 'div'
6-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call at() on empty Wrapper`
7-
const error = new ErrorWrapper(selector)
8-
expect(() => error.at()).to.throw().with.property('message', message)
9-
})
10-
11-
it('attributes throws error when called', () => {
12-
const selector = 'div'
13-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call attributes() on empty Wrapper`
14-
const error = new ErrorWrapper(selector)
15-
expect(() => error.attributes()).to.throw().with.property('message', message)
16-
})
17-
18-
it('classes throws error when called', () => {
19-
const selector = 'div'
20-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call classes() on empty Wrapper`
21-
const error = new ErrorWrapper(selector)
22-
expect(() => error.classes()).to.throw().with.property('message', message)
23-
})
24-
25-
it('contains throws error when called', () => {
26-
const selector = 'div'
27-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call contains() on empty Wrapper`
28-
const error = new ErrorWrapper(selector)
29-
expect(() => error.contains()).to.throw().with.property('message', message)
30-
})
31-
32-
it('emitted throws error when called', () => {
33-
const selector = 'div'
34-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call emitted() on empty Wrapper`
35-
const error = new ErrorWrapper(selector)
36-
expect(() => error.emitted()).to.throw().with.property('message', message)
37-
})
38-
39-
it('emittedByOrder throws error when called', () => {
40-
const selector = 'div'
41-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call emittedByOrder() on empty Wrapper`
42-
const error = new ErrorWrapper(selector)
43-
expect(() => error.emittedByOrder()).to.throw().with.property('message', message)
44-
})
45-
46-
it('hasAttribute throws error when called', () => {
47-
const selector = 'div'
48-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call hasAttribute() on empty Wrapper`
49-
const error = new ErrorWrapper(selector)
50-
expect(() => error.hasAttribute()).to.throw().with.property('message', message)
51-
})
52-
53-
it('hasClass throws error when called', () => {
54-
const selector = 'div'
55-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call hasClass() on empty Wrapper`
56-
const error = new ErrorWrapper(selector)
57-
expect(() => error.hasClass()).to.throw().with.property('message', message)
58-
})
59-
60-
it('hasProp throws error when called', () => {
61-
const selector = 'div'
62-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call hasProp() on empty Wrapper`
63-
const error = new ErrorWrapper(selector)
64-
expect(() => error.hasProp()).to.throw().with.property('message', message)
65-
})
66-
67-
it('hasStyle throws error when called', () => {
68-
const selector = 'div'
69-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call hasStyle() on empty Wrapper`
70-
const error = new ErrorWrapper(selector)
71-
expect(() => error.hasStyle()).to.throw().with.property('message', message)
72-
})
73-
74-
it('findAll throws error when called', () => {
75-
const selector = 'div'
76-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call findAll() on empty Wrapper`
77-
const error = new ErrorWrapper(selector)
78-
expect(() => error.findAll()).to.throw().with.property('message', message)
79-
})
80-
81-
it('find throws error when called', () => {
82-
const selector = 'div'
83-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call find() on empty Wrapper`
84-
const error = new ErrorWrapper(selector)
85-
expect(() => error.find()).to.throw().with.property('message', message)
86-
})
87-
88-
it('html throws error when called', () => {
89-
const selector = 'div'
90-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call html() on empty Wrapper`
91-
const error = new ErrorWrapper(selector)
92-
expect(() => error.html()).to.throw().with.property('message', message)
93-
})
94-
95-
it('is throws error when called', () => {
96-
const selector = 'div'
97-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call is() on empty Wrapper`
98-
const error = new ErrorWrapper(selector)
99-
expect(() => error.is()).to.throw().with.property('message', message)
100-
})
101-
102-
it('isEmpty throws error when called', () => {
103-
const selector = 'div'
104-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call isEmpty() on empty Wrapper`
105-
const error = new ErrorWrapper(selector)
106-
expect(() => error.isEmpty()).to.throw().with.property('message', message)
107-
})
108-
109-
it('isVueInstance throws error when called', () => {
110-
const selector = 'div'
111-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call isVueInstance() on empty Wrapper`
112-
const error = new ErrorWrapper(selector)
113-
expect(() => error.isVueInstance()).to.throw().with.property('message', message)
114-
})
115-
116-
it('name throws error when called', () => {
117-
const selector = 'div'
118-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call name() on empty Wrapper`
119-
const error = new ErrorWrapper(selector)
120-
expect(() => error.name()).to.throw().with.property('message', message)
121-
})
122-
123-
it('props throws error when called', () => {
124-
const selector = 'div'
125-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call props() on empty Wrapper`
126-
const error = new ErrorWrapper(selector)
127-
expect(() => error.props()).to.throw().with.property('message', message)
128-
})
129-
130-
it('text throws error when called', () => {
131-
const selector = 'div'
132-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call text() on empty Wrapper`
133-
const error = new ErrorWrapper(selector)
134-
expect(() => error.text()).to.throw().with.property('message', message)
135-
})
136-
137-
it('setComputed throws error when called', () => {
138-
const selector = 'div'
139-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call setComputed() on empty Wrapper`
140-
const error = new ErrorWrapper(selector)
141-
expect(() => error.setComputed()).to.throw().with.property('message', message)
142-
})
143-
144-
it('setData throws error when called', () => {
145-
const selector = 'div'
146-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call setData() on empty Wrapper`
147-
const error = new ErrorWrapper(selector)
148-
expect(() => error.setData()).to.throw().with.property('message', message)
149-
})
150-
151-
it('setMethods throws error when called', () => {
152-
const selector = 'div'
153-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call setMethods() on empty Wrapper`
154-
const error = new ErrorWrapper(selector)
155-
expect(() => error.setMethods()).to.throw().with.property('message', message)
156-
})
157-
158-
it('setProps throws error when called', () => {
159-
const selector = 'div'
160-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call setProps() on empty Wrapper`
161-
const error = new ErrorWrapper(selector)
162-
expect(() => error.setProps()).to.throw().with.property('message', message)
163-
})
164-
165-
it('trigger throws error when called', () => {
166-
const selector = 'div'
167-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call trigger() on empty Wrapper`
168-
const error = new ErrorWrapper(selector)
169-
expect(() => error.trigger()).to.throw().with.property('message', message)
170-
})
171-
172-
it('update throws error when called', () => {
173-
const selector = 'div'
174-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call update() on empty Wrapper`
175-
const error = new ErrorWrapper(selector)
176-
expect(() => error.update()).to.throw().with.property('message', message)
177-
})
178-
179-
it('destroy throws error when called', () => {
180-
const selector = 'div'
181-
const message = `[vue-test-utils]: find did not return ${selector}, cannot call destroy() on empty Wrapper`
182-
const error = new ErrorWrapper(selector)
183-
expect(() => error.destroy()).to.throw().with.property('message', message)
5+
const methods = ['at', 'attributes', 'classes', 'contains', 'emitted', 'emittedByOrder', 'hasAttribute',
6+
'hasClass', 'hasProp', 'hasStyle', 'find', 'findAll', 'html', 'text', 'is', 'isEmpty', 'isVueInstance', 'isEmpty',
7+
'name', 'props', 'setComputed', 'setMethods', 'setData', 'setProps', 'trigger', 'update', 'destroy']
8+
methods.forEach((method) => {
9+
it(`${method} throws error when called`, () => {
10+
const compiled = compileToFunctions('<p />')
11+
const selector = 'div'
12+
const message = `[vue-test-utils]: find did not return ${selector}, cannot call ${method}() on empty Wrapper`
13+
const wrapper = mount(compiled)
14+
const error = wrapper.find(selector)
15+
expect(error.constructor.name).to.equal('ErrorWrapper')
16+
expect(() => error[method]()).to.throw().with.property('message', message)
17+
})
18418
})
18519
})

0 commit comments

Comments
 (0)