Skip to content

Commit

Permalink
Add test that local mocks override config mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiller1990 committed Apr 18, 2018
1 parent 88a20f4 commit 7cd229c
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion test/specs/mounting-options/mocks.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createLocalVue } from '~vue/test-utils'
import { createLocalVue, config } from '~vue/test-utils'
import Component from '~resources/components/component.vue'
import ComponentWithVuex from '~resources/components/component-with-vuex.vue'
import {
Expand All @@ -7,6 +7,21 @@ import {
} from '~resources/utils'

describeWithMountingMethods('options.mocks', (mountingMethod) => {
let configStubsSave
// let serverConfigSave

beforeEach(() => {
configStubsSave = config.stubs
// serverConfigSave = serverConfig.stubs
config.stubs = {}
// serverConfig.stubs = {}
})

afterEach(() => {
config.stubs = configStubsSave
// serverConfig.stubs = serverConfigSave
})

it('adds variables to vm when passed', () => {
const TestComponent = {
template: `
Expand Down Expand Up @@ -127,6 +142,29 @@ describeWithMountingMethods('options.mocks', (mountingMethod) => {
error.restore()
})

it('prioritize mounting options over config', () => {
config.mocks['$global'] = 'globallyMockedValue'

const localVue = createLocalVue()
const TestComponent = {
template: `
<div>{{ $global }}</div>
`
}

const wrapper = mountingMethod(TestComponent, {
localVue,
mocks: {
'$global': 'locallyMockedValue'
}
})
const HTML = mountingMethod.name === 'renderToString'
? wrapper
: wrapper.html()
console.log(wrapper)
expect(HTML).to.contain('locallyMockedValue')
})

it('logs that a property cannot be overwritten if there are problems writing', () => {
const error = sinon.stub(console, 'error')
const localVue = createLocalVue()
Expand Down

0 comments on commit 7cd229c

Please sign in to comment.