Skip to content

Commit 5697fea

Browse files
authored
fix: log key that cannot be overwritten (#367)
1 parent 807fd68 commit 5697fea

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/lib/add-mocks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default function addMocks (mockedProperties: Object, Vue: Component) {
77
try {
88
Vue.prototype[key] = mockedProperties[key]
99
} catch (e) {
10-
warn('could not overwrite property $store, this usually caused by a plugin that has added the property as a read-only value')
10+
warn(`could not overwrite property ${key}, this usually caused by a plugin that has added the property as a read-only value`)
1111
}
1212
$$Vue.util.defineReactive(Vue, key, mockedProperties[key])
1313
})

test/unit/specs/mount/options/mocks.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,22 @@ describe('mount.mocks', () => {
102102
expect(error.calledWith(msg)).to.equal(true)
103103
error.restore()
104104
})
105+
106+
it('logs that a property cannot be overwritten if there are problems writing', () => {
107+
const error = sinon.stub(console, 'error')
108+
const localVue = createLocalVue()
109+
Object.defineProperty(localVue.prototype, '$val', {
110+
value: 42
111+
})
112+
const $val = 64
113+
mount(Component, {
114+
localVue,
115+
mocks: {
116+
$val
117+
}
118+
})
119+
const msg = '[vue-test-utils]: could not overwrite property $val, this usually caused by a plugin that has added the property as a read-only value'
120+
expect(error.calledWith(msg)).to.equal(true)
121+
error.restore()
122+
})
105123
})

0 commit comments

Comments
 (0)