Skip to content

Commit 31d1f7a

Browse files
committed
Add test to ensure local methods override config
1 parent 7cd229c commit 31d1f7a

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { config } from '~vue/test-utils'
2+
import {
3+
describeWithMountingMethods
4+
} from '~resources/utils'
5+
6+
describeWithMountingMethods('options.methods', (mountingMethod) => {
7+
it('prioritize mounting options over config', () => {
8+
config.methods['val'] = () => 'methodFromConfig'
9+
10+
const TestComponent = {
11+
template: `
12+
<div>{{ val() }}</div>
13+
`
14+
}
15+
16+
const wrapper = mountingMethod(TestComponent, {
17+
methods: {
18+
val () {
19+
return 'methodFromOptions'
20+
}
21+
}
22+
})
23+
const HTML = mountingMethod.name === 'renderToString'
24+
? wrapper
25+
: wrapper.html()
26+
console.log(wrapper)
27+
expect(HTML).to.contain('methodFromOptions')
28+
})
29+
})

test/specs/mounting-options/mocks.spec.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,15 @@ import {
77
} from '~resources/utils'
88

99
describeWithMountingMethods('options.mocks', (mountingMethod) => {
10-
let configStubsSave
11-
// let serverConfigSave
10+
let configMocksSave
1211

1312
beforeEach(() => {
14-
configStubsSave = config.stubs
15-
// serverConfigSave = serverConfig.stubs
16-
config.stubs = {}
17-
// serverConfig.stubs = {}
13+
configMocksSave = config.mocks
14+
config.mocks = {}
1815
})
1916

2017
afterEach(() => {
21-
config.stubs = configStubsSave
22-
// serverConfig.stubs = serverConfigSave
18+
config.mocks = configMocksSave
2319
})
2420

2521
it('adds variables to vm when passed', () => {
@@ -145,15 +141,13 @@ describeWithMountingMethods('options.mocks', (mountingMethod) => {
145141
it('prioritize mounting options over config', () => {
146142
config.mocks['$global'] = 'globallyMockedValue'
147143

148-
const localVue = createLocalVue()
149144
const TestComponent = {
150145
template: `
151146
<div>{{ $global }}</div>
152147
`
153148
}
154149

155150
const wrapper = mountingMethod(TestComponent, {
156-
localVue,
157151
mocks: {
158152
'$global': 'locallyMockedValue'
159153
}

0 commit comments

Comments
 (0)