Skip to content

Commit

Permalink
fix: clone propsData to avoid mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
briwa committed May 15, 2018
1 parent 934745b commit b5c9a3e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
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 b5c9a3e

Please sign in to comment.