Skip to content

Commit 4473d2e

Browse files
committed
fix: clone propsData to avoid mutation
1 parent 934745b commit 4473d2e

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

Diff for: packages/create-instance/create-instance.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default function createInstance (
5757

5858
const Constructor = vue.extend(component)
5959

60-
const instanceOptions = { ...options }
60+
const instanceOptions = { ...options, propsData : { ...options.propsData } }
6161
deleteoptions(instanceOptions)
6262
// $FlowIgnore
6363
const stubComponents = createComponentStubs(component.components, options.stubs)

Diff for: test/specs/mounting-options/propsData.spec.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { shallowMount } from '~vue/test-utils'
2+
import ComponentWithProps from '~resources/components/component-with-props.vue'
3+
import { describeIf } from '~resources/utils'
4+
5+
const baseData = {
6+
prop1: ['', '']
7+
}
8+
9+
describeIf(process.env.TEST_ENV !== 'node',
10+
'propsData', () => {
11+
let wrapper
12+
13+
beforeEach(() => {
14+
wrapper = shallowMount(ComponentWithProps, {
15+
propsData : baseData,
16+
})
17+
})
18+
19+
afterEach(() => {
20+
wrapper = null
21+
})
22+
23+
describe('should not modify propsData between tests', () => {
24+
it('should have the correct props after modifying', () => {
25+
expect(wrapper.vm.prop1).to.have.length(2)
26+
wrapper.setProps({ prop1: [] });
27+
expect(wrapper.vm.prop1).to.have.length(0)
28+
})
29+
30+
it('should have the default props despite being modified in the previous test', () => {
31+
expect(wrapper.vm.prop1).to.have.length(2)
32+
})
33+
})
34+
})

0 commit comments

Comments
 (0)