diff --git a/src/lib/add-mocks.js b/src/lib/add-mocks.js index 537976283..33e527e86 100644 --- a/src/lib/add-mocks.js +++ b/src/lib/add-mocks.js @@ -7,7 +7,7 @@ export default function addMocks (mockedProperties: Object, Vue: Component) { try { Vue.prototype[key] = mockedProperties[key] } catch (e) { - warn('could not overwrite property $store, this usually caused by a plugin that has added the property as a read-only value') + warn(`could not overwrite property ${key}, this usually caused by a plugin that has added the property as a read-only value`) } $$Vue.util.defineReactive(Vue, key, mockedProperties[key]) }) diff --git a/test/unit/specs/mount/options/mocks.spec.js b/test/unit/specs/mount/options/mocks.spec.js index e54bf5546..c175495e8 100644 --- a/test/unit/specs/mount/options/mocks.spec.js +++ b/test/unit/specs/mount/options/mocks.spec.js @@ -102,4 +102,22 @@ describe('mount.mocks', () => { expect(error.calledWith(msg)).to.equal(true) error.restore() }) + + it('logs that a property cannot be overwritten if there are problems writing', () => { + const error = sinon.stub(console, 'error') + const localVue = createLocalVue() + Object.defineProperty(localVue.prototype, '$val', { + value: 42 + }) + const $val = 64 + mount(Component, { + localVue, + mocks: { + $val + } + }) + 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' + expect(error.calledWith(msg)).to.equal(true) + error.restore() + }) })