Skip to content

Commit a93275c

Browse files
briwaeddyerburgh
briwa
authored andcommitted
fix: clone propsData to avoid mutation (#613)
1 parent 7c5a2dc commit a93275c

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

Diff for: flow/options.flow.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
declare type Options = { // eslint-disable-line no-undef
22
attachToDocument?: boolean,
3+
propsData?: Object,
34
mocks?: Object,
45
methods?: Object,
56
slots?: Object,

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)