Skip to content

Commit

Permalink
fix: clone propsData to avoid mutation (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
briwa authored and eddyerburgh committed May 16, 2018
1 parent 7c5a2dc commit a93275c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions flow/options.flow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
declare type Options = { // eslint-disable-line no-undef
attachToDocument?: boolean,
propsData?: Object,
mocks?: Object,
methods?: Object,
slots?: Object,
Expand Down
2 changes: 1 addition & 1 deletion packages/create-instance/create-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default function createInstance (

const Constructor = vue.extend(component)

const instanceOptions = { ...options }
const instanceOptions = { ...options, propsData: { ...options.propsData }}
deleteoptions(instanceOptions)
// $FlowIgnore
const stubComponents = createComponentStubs(component.components, options.stubs)
Expand Down
34 changes: 34 additions & 0 deletions test/specs/mounting-options/propsData.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { shallowMount } from '~vue/test-utils'
import ComponentWithProps from '~resources/components/component-with-props.vue'
import { describeIf } from '~resources/utils'

const baseData = {
prop1: ['', '']
}

describeIf(process.env.TEST_ENV !== 'node',
'propsData', () => {
let wrapper

beforeEach(() => {
wrapper = shallowMount(ComponentWithProps, {
propsData: baseData
})
})

afterEach(() => {
wrapper = null
})

describe('should not modify propsData between tests', () => {
it('should have the correct props after modifying', () => {
expect(wrapper.vm.prop1).to.have.length(2)
wrapper.setProps({ prop1: [] })
expect(wrapper.vm.prop1).to.have.length(0)
})

it('should have the default props despite being modified in the previous test', () => {
expect(wrapper.vm.prop1).to.have.length(2)
})
})
})

0 comments on commit a93275c

Please sign in to comment.