Skip to content

Commit f29fbe5

Browse files
lmiller1990AtofStryker
authored andcommitted
test: update mount specs
1 parent 495e127 commit f29fbe5

File tree

3 files changed

+33
-40
lines changed

3 files changed

+33
-40
lines changed

test/specs/create-wrapper.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => {
99
const vm = new Constructor().$mount()
1010
const wrapper = createWrapper(vm)
1111
expect(wrapper.is(Component)).toEqual(true)
12-
expect(wrapper).instanceof(Wrapper)
13-
expect(wrapper.findAll('div')).instanceof(WrapperArray)
12+
expect(wrapper).toBeInstanceOf(Wrapper)
13+
expect(wrapper.findAll('div')).toBeInstanceOf(WrapperArray)
1414
})
1515

1616
it('handles HTMLElement', () => {

test/specs/mount.spec.js

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,12 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => {
122122
)
123123

124124
it('does not use cached component', () => {
125-
jest.fn()(ComponentWithMixin.methods, 'someMethod')
125+
ComponentWithMixin.methods.someMethod = jest.fn()
126126
mount(ComponentWithMixin)
127-
expect(ComponentWithMixin.methods.someMethod.callCount).toEqual(1)
128-
ComponentWithMixin.methods.someMethod.restore()
129-
jest.fn()(ComponentWithMixin.methods, 'someMethod')
127+
expect(ComponentWithMixin.methods.someMethod).toHaveBeenCalledTimes(1)
128+
ComponentWithMixin.methods.someMethod = jest.fn()
130129
mount(ComponentWithMixin)
131-
expect(ComponentWithMixin.methods.someMethod.callCount).toEqual(1)
130+
expect(ComponentWithMixin.methods.someMethod).toHaveBeenCalledTimes(1)
132131
})
133132

134133
it('throws an error if window is undefined', () => {
@@ -188,32 +187,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => {
188187
}
189188
}).vm.callStub()
190189

191-
expect(stub).not.called
192-
})
193-
194-
it.skip('overrides component prototype', () => {
195-
const mountSpy = sandbox.spy()
196-
const destroySpy = sandbox.spy()
197-
const Component = Vue.extend({})
198-
const {
199-
$mount: originalMount,
200-
$destroy: originalDestroy
201-
} = Component.prototype
202-
Component.prototype.$mount = function(...args) {
203-
originalMount.apply(this, args)
204-
mountSpy()
205-
return this
206-
}
207-
Component.prototype.$destroy = function() {
208-
originalDestroy.apply(this)
209-
destroySpy()
210-
}
211-
212-
const wrapper = mount(Component)
213-
expect(mountSpy).called
214-
expect(destroySpy).not.called
215-
wrapper.destroy()
216-
expect(destroySpy).called
190+
expect(stub).not.toHaveBeenCalled()
217191
})
218192

219193
// Problems accessing options of twice extended components in Vue < 2.3

test/specs/shallow-mount.spec.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ import { vueVersion } from '~resources/utils'
1515
import { describeRunIf, itDoNotRunIf } from 'conditional-specs'
1616

1717
describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
18+
let consoleInfoSave = console.info
19+
let consoleErrorSave = console.error
20+
21+
beforeEach(() => {
22+
consoleInfoSave = console.info
23+
consoleErrorSave = console.error
24+
console.info = jest.fn()
25+
console.error = jest.fn()
26+
})
27+
28+
afterEach(() => {
29+
console.info = consoleInfoSave
30+
console.error = consoleErrorSave
31+
})
32+
1833
it('renders dynamic class of functional child', () => {
1934
const wrapper = shallowMount(ComponentWithFunctionalChild)
2035
expect(wrapper.find('functional-component-stub').classes()).toContain(
@@ -58,7 +73,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
5873
localVue.component('registered-component', ComponentWithLifecycleHooks)
5974
mount(TestComponent, { localVue })
6075

61-
expect(console.info.callCount).toEqual(4)
76+
expect(console.info).toHaveBeenCalledTimes(4)
6277
})
6378

6479
it('renders children', () => {
@@ -167,7 +182,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
167182
shallowMount(Component)
168183
mount(Component)
169184

170-
expect(console.info.callCount).toEqual(4)
185+
expect(console.info).toHaveBeenCalledTimes(4)
171186
})
172187

173188
itDoNotRunIf(
@@ -192,7 +207,9 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
192207
}
193208
}
194209
shallowMount(TestComponent)
195-
expect(console.error).not.calledWith(sandbox.match('[Vue warn]'))
210+
expect(console.error).not.toHaveBeenCalledWith(
211+
expect.stringMatching('[Vue warn]')
212+
)
196213
}
197214
)
198215

@@ -297,12 +314,14 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
297314
}
298315
const wrapper = shallowMount(TestComponent)
299316
expect(wrapper.html()).toContain('<test-component-stub>')
300-
expect(console.error).not.calledWith('[Vue warn]')
317+
expect(console.error).not.toHaveBeenCalledWith(
318+
expect.stringMatching('[Vue warn]')
319+
)
301320
})
302321

303322
it('does not call stubbed children lifecycle hooks', () => {
304323
shallowMount(ComponentWithNestedChildren)
305-
expect(console.info.called).toEqual(false)
324+
expect(console.info).not.toHaveBeenCalled()
306325
})
307326

308327
it('stubs extended components', () => {
@@ -591,8 +610,8 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
591610
}
592611
shallowMount(TestComponent)
593612
mount(TestComponent)
594-
expect(console.error).not.calledWith(
595-
sandbox.match('Unknown custom element')
613+
expect(console.error).not.toHaveBeenCalledWith(
614+
expect.stringMatching('Unknown custom element')
596615
)
597616
}
598617
)

0 commit comments

Comments
 (0)