Fixed naming in SpyRegistry specs

This commit is contained in:
Steve Gravrock
2025-09-25 20:41:19 -07:00
parent 8863643d55
commit 979e4a5d0f

View File

@@ -15,10 +15,10 @@ describe('SpyRegistry', function() {
it('checks that a method name was passed', function() { it('checks that a method name was passed', function() {
const spyRegistry = new jasmineUnderTest.SpyRegistry(), const spyRegistry = new jasmineUnderTest.SpyRegistry(),
subject = {}; target = {};
expect(function() { expect(function() {
spyRegistry.spyOn(subject); spyRegistry.spyOn(target);
}).toThrowError(/No method name supplied/); }).toThrowError(/No method name supplied/);
}); });
@@ -31,19 +31,19 @@ describe('SpyRegistry', function() {
it('checks that the method name is not `null`', function() { it('checks that the method name is not `null`', function() {
const spyRegistry = new jasmineUnderTest.SpyRegistry(), const spyRegistry = new jasmineUnderTest.SpyRegistry(),
subject = {}; target = {};
expect(function() { expect(function() {
spyRegistry.spyOn(subject, null); spyRegistry.spyOn(target, null);
}).toThrowError(/No method name supplied/); }).toThrowError(/No method name supplied/);
}); });
it('checks for the existence of the method', function() { it('checks for the existence of the method', function() {
const spyRegistry = new jasmineUnderTest.SpyRegistry(), const spyRegistry = new jasmineUnderTest.SpyRegistry(),
subject = {}; target = {};
expect(function() { expect(function() {
spyRegistry.spyOn(subject, 'pants'); spyRegistry.spyOn(target, 'pants');
}).toThrowError(/method does not exist/); }).toThrowError(/method does not exist/);
}); });
@@ -55,12 +55,12 @@ describe('SpyRegistry', function() {
}, },
createSpy: createSpy createSpy: createSpy
}), }),
subject = { spiedFunc: function() {} }; target = { spiedFunc: function() {} };
spyRegistry.spyOn(subject, 'spiedFunc'); spyRegistry.spyOn(target, 'spiedFunc');
expect(function() { expect(function() {
spyRegistry.spyOn(subject, 'spiedFunc'); spyRegistry.spyOn(target, 'spiedFunc');
}).toThrowError(/has already been spied upon/); }).toThrowError(/has already been spied upon/);
}); });
@@ -83,14 +83,14 @@ describe('SpyRegistry', function() {
return spies; return spies;
} }
}), }),
subject = { spiedFunc: scope.myFunc }; target = { spiedFunc: scope.myFunc };
expect(function() { expect(function() {
spyRegistry.spyOn(scope, 'myFunc'); spyRegistry.spyOn(scope, 'myFunc');
}).toThrowError(/is not declared writable or has no setter/); }).toThrowError(/is not declared writable or has no setter/);
expect(function() { expect(function() {
spyRegistry.spyOn(subject, 'spiedFunc'); spyRegistry.spyOn(target, 'spiedFunc');
}).not.toThrowError(/is not declared writable or has no setter/); }).not.toThrowError(/is not declared writable or has no setter/);
}); });
@@ -123,16 +123,16 @@ describe('SpyRegistry', function() {
const spyRegistry = new jasmineUnderTest.SpyRegistry({ const spyRegistry = new jasmineUnderTest.SpyRegistry({
createSpy: createSpy createSpy: createSpy
}); });
const subject = { const target = {
spiedFunc: function() { spiedFunc: function() {
originalFunctionWasCalled = true; originalFunctionWasCalled = true;
} }
}; };
const spy = spyRegistry.spyOn(subject, 'spiedFunc'); const spy = spyRegistry.spyOn(target, 'spiedFunc');
expect(subject.spiedFunc).toEqual(spy); expect(target.spiedFunc).toEqual(spy);
subject.spiedFunc(); target.spiedFunc();
expect(originalFunctionWasCalled).toBe(false); expect(originalFunctionWasCalled).toBe(false);
}); });
}); });
@@ -147,27 +147,27 @@ describe('SpyRegistry', function() {
it('checks that a property name was passed', function() { it('checks that a property name was passed', function() {
const spyRegistry = new jasmineUnderTest.SpyRegistry(), const spyRegistry = new jasmineUnderTest.SpyRegistry(),
subject = {}; target = {};
expect(function() { expect(function() {
spyRegistry.spyOnProperty(subject); spyRegistry.spyOnProperty(target);
}).toThrowError(/No property name supplied/); }).toThrowError(/No property name supplied/);
}); });
it('checks for the existence of the method', function() { it('checks for the existence of the method', function() {
const spyRegistry = new jasmineUnderTest.SpyRegistry(), const spyRegistry = new jasmineUnderTest.SpyRegistry(),
subject = {}; target = {};
expect(function() { expect(function() {
spyRegistry.spyOnProperty(subject, 'pants'); spyRegistry.spyOnProperty(target, 'pants');
}).toThrowError(/property does not exist/); }).toThrowError(/property does not exist/);
}); });
it('checks for the existence of access type', function() { it('checks for the existence of access type', function() {
const spyRegistry = new jasmineUnderTest.SpyRegistry(), const spyRegistry = new jasmineUnderTest.SpyRegistry(),
subject = {}; target = {};
Object.defineProperty(subject, 'pants', { Object.defineProperty(target, 'pants', {
get: function() { get: function() {
return 1; return 1;
}, },
@@ -175,18 +175,18 @@ describe('SpyRegistry', function() {
}); });
expect(function() { expect(function() {
spyRegistry.spyOnProperty(subject, 'pants', 'set'); spyRegistry.spyOnProperty(target, 'pants', 'set');
}).toThrowError(/does not have access type/); }).toThrowError(/does not have access type/);
}); });
it('checks if it can be spied upon', function() { it('checks if it can be spied upon', function() {
const subject = {}; const target = {};
Object.defineProperty(subject, 'myProp', { Object.defineProperty(target, 'myProp', {
get: function() {} get: function() {}
}); });
Object.defineProperty(subject, 'spiedProp', { Object.defineProperty(target, 'spiedProp', {
get: function() {}, get: function() {},
configurable: true configurable: true
}); });
@@ -194,11 +194,11 @@ describe('SpyRegistry', function() {
const spyRegistry = new jasmineUnderTest.SpyRegistry(); const spyRegistry = new jasmineUnderTest.SpyRegistry();
expect(function() { expect(function() {
spyRegistry.spyOnProperty(subject, 'myProp'); spyRegistry.spyOnProperty(target, 'myProp');
}).toThrowError(/is not declared configurable/); }).toThrowError(/is not declared configurable/);
expect(function() { expect(function() {
spyRegistry.spyOnProperty(subject, 'spiedProp'); spyRegistry.spyOnProperty(target, 'spiedProp');
}).not.toThrowError(/is not declared configurable/); }).not.toThrowError(/is not declared configurable/);
}); });
@@ -206,34 +206,34 @@ describe('SpyRegistry', function() {
const spyRegistry = new jasmineUnderTest.SpyRegistry({ const spyRegistry = new jasmineUnderTest.SpyRegistry({
createSpy: createSpy createSpy: createSpy
}), }),
subject = {}, target = {},
returnValue = 1; returnValue = 1;
Object.defineProperty(subject, 'spiedProperty', { Object.defineProperty(target, 'spiedProperty', {
get: function() { get: function() {
return returnValue; return returnValue;
}, },
configurable: true configurable: true
}); });
expect(subject.spiedProperty).toEqual(returnValue); expect(target.spiedProperty).toEqual(returnValue);
const spy = spyRegistry.spyOnProperty(subject, 'spiedProperty'); const spy = spyRegistry.spyOnProperty(target, 'spiedProperty');
const getter = Object.getOwnPropertyDescriptor(subject, 'spiedProperty') const getter = Object.getOwnPropertyDescriptor(target, 'spiedProperty')
.get; .get;
expect(getter).toEqual(spy); expect(getter).toEqual(spy);
expect(subject.spiedProperty).toBeUndefined(); expect(target.spiedProperty).toBeUndefined();
}); });
it('overrides the property setter on the object and returns the spy', function() { it('overrides the property setter on the object and returns the spy', function() {
const spyRegistry = new jasmineUnderTest.SpyRegistry({ const spyRegistry = new jasmineUnderTest.SpyRegistry({
createSpy: createSpy createSpy: createSpy
}), }),
subject = {}, target = {},
returnValue = 1; returnValue = 1;
Object.defineProperty(subject, 'spiedProperty', { Object.defineProperty(target, 'spiedProperty', {
get: function() { get: function() {
return returnValue; return returnValue;
}, },
@@ -241,11 +241,11 @@ describe('SpyRegistry', function() {
configurable: true configurable: true
}); });
const spy = spyRegistry.spyOnProperty(subject, 'spiedProperty', 'set'); const spy = spyRegistry.spyOnProperty(target, 'spiedProperty', 'set');
const setter = Object.getOwnPropertyDescriptor(subject, 'spiedProperty') const setter = Object.getOwnPropertyDescriptor(target, 'spiedProperty')
.set; .set;
expect(subject.spiedProperty).toEqual(returnValue); expect(target.spiedProperty).toEqual(returnValue);
expect(setter).toEqual(spy); expect(setter).toEqual(spy);
}); });
@@ -254,19 +254,19 @@ describe('SpyRegistry', function() {
const spyRegistry = new jasmineUnderTest.SpyRegistry({ const spyRegistry = new jasmineUnderTest.SpyRegistry({
createSpy: createSpy createSpy: createSpy
}), }),
subject = {}; target = {};
Object.defineProperty(subject, 'spiedProp', { Object.defineProperty(target, 'spiedProp', {
get: function() { get: function() {
return 1; return 1;
}, },
configurable: true configurable: true
}); });
spyRegistry.spyOnProperty(subject, 'spiedProp'); spyRegistry.spyOnProperty(target, 'spiedProp');
expect(function() { expect(function() {
spyRegistry.spyOnProperty(subject, 'spiedProp'); spyRegistry.spyOnProperty(target, 'spiedProp');
}).toThrowError(/spiedProp#get has already been spied upon/); }).toThrowError(/spiedProp#get has already been spied upon/);
}); });
@@ -274,20 +274,20 @@ describe('SpyRegistry', function() {
const spyRegistry = new jasmineUnderTest.SpyRegistry({ const spyRegistry = new jasmineUnderTest.SpyRegistry({
createSpy: createSpy createSpy: createSpy
}), }),
subject = {}; target = {};
spyRegistry.allowRespy(true); spyRegistry.allowRespy(true);
Object.defineProperty(subject, 'spiedProp', { Object.defineProperty(target, 'spiedProp', {
get: function() { get: function() {
return 1; return 1;
}, },
configurable: true configurable: true
}); });
const originalSpy = spyRegistry.spyOnProperty(subject, 'spiedProp'); const originalSpy = spyRegistry.spyOnProperty(target, 'spiedProp');
expect(spyRegistry.spyOnProperty(subject, 'spiedProp')).toBe( expect(spyRegistry.spyOnProperty(target, 'spiedProp')).toBe(
originalSpy originalSpy
); );
}); });
@@ -322,21 +322,21 @@ describe('SpyRegistry', function() {
const parent = { const parent = {
parentSpied1: noop1 parentSpied1: noop1
}; };
const subject = Object.create(parent); const target = Object.create(parent);
Object.defineProperty(subject, 'spied1', { Object.defineProperty(target, 'spied1', {
value: noop1, value: noop1,
writable: true, writable: true,
configurable: true, configurable: true,
enumerable: true enumerable: true
}); });
Object.defineProperty(subject, 'spied2', { Object.defineProperty(target, 'spied2', {
value: noop2, value: noop2,
writable: true, writable: true,
configurable: true, configurable: true,
enumerable: true enumerable: true
}); });
let _spied3 = noop3; let _spied3 = noop3;
Object.defineProperty(subject, 'spied3', { Object.defineProperty(target, 'spied3', {
configurable: true, configurable: true,
set: function(val) { set: function(val) {
_spied3 = val; _spied3 = val;
@@ -346,20 +346,20 @@ describe('SpyRegistry', function() {
}, },
enumerable: true enumerable: true
}); });
subject.spied4 = noop4; target.spied4 = noop4;
Object.defineProperty(subject, 'notSpied2', { Object.defineProperty(target, 'notSpied2', {
value: noop2, value: noop2,
writable: false, writable: false,
configurable: true, configurable: true,
enumerable: true enumerable: true
}); });
Object.defineProperty(subject, 'notSpied3', { Object.defineProperty(target, 'notSpied3', {
value: noop3, value: noop3,
writable: true, writable: true,
configurable: false, configurable: false,
enumerable: true enumerable: true
}); });
Object.defineProperty(subject, 'notSpied4', { Object.defineProperty(target, 'notSpied4', {
configurable: false, configurable: false,
set: function() { set: function() {
/**/ /**/
@@ -369,27 +369,27 @@ describe('SpyRegistry', function() {
}, },
enumerable: true enumerable: true
}); });
Object.defineProperty(subject, 'notSpied5', { Object.defineProperty(target, 'notSpied5', {
value: noop5, value: noop5,
writable: true, writable: true,
configurable: true, configurable: true,
enumerable: false enumerable: false
}); });
subject.notSpied6 = 6; target.notSpied6 = 6;
const spiedObject = spyRegistry.spyOnAllFunctions(subject); const spiedObject = spyRegistry.spyOnAllFunctions(target);
expect(subject.parentSpied1).toBe('I am a spy'); expect(target.parentSpied1).toBe('I am a spy');
expect(subject.notSpied2).toBe(noop2); expect(target.notSpied2).toBe(noop2);
expect(subject.notSpied3).toBe(noop3); expect(target.notSpied3).toBe(noop3);
expect(subject.notSpied4).toBe(noop4); expect(target.notSpied4).toBe(noop4);
expect(subject.notSpied5).toBe(noop5); expect(target.notSpied5).toBe(noop5);
expect(subject.notSpied6).toBe(6); expect(target.notSpied6).toBe(6);
expect(subject.spied1).toBe('I am a spy'); expect(target.spied1).toBe('I am a spy');
expect(subject.spied2).toBe('I am a spy'); expect(target.spied2).toBe('I am a spy');
expect(subject.spied3).toBe('I am a spy'); expect(target.spied3).toBe('I am a spy');
expect(subject.spied4).toBe('I am a spy'); expect(target.spied4).toBe('I am a spy');
expect(spiedObject).toBe(subject); expect(spiedObject).toBe(target);
}); });
it('overrides prototype methods on the object', function() { it('overrides prototype methods on the object', function() {
@@ -407,11 +407,11 @@ describe('SpyRegistry', function() {
}; };
MyClass.prototype.spied2 = noop2; MyClass.prototype.spied2 = noop2;
const subject = new MyClass(); const target = new MyClass();
spyRegistry.spyOnAllFunctions(subject); spyRegistry.spyOnAllFunctions(target);
expect(subject.spied1).toBe('I am a spy'); expect(target.spied1).toBe('I am a spy');
expect(subject.spied2).toBe('I am a spy'); expect(target.spied2).toBe('I am a spy');
expect(MyClass.prototype.spied2).toBe(noop2); expect(MyClass.prototype.spied2).toBe(noop2);
}); });
@@ -421,15 +421,15 @@ describe('SpyRegistry', function() {
return 'I am a spy'; return 'I am a spy';
} }
}); });
const subject = { const target = {
spied1: function() {} spied1: function() {}
}; };
spyRegistry.spyOnAllFunctions(subject); spyRegistry.spyOnAllFunctions(target);
expect(subject.spied1).toBe('I am a spy'); expect(target.spied1).toBe('I am a spy');
expect(subject.toString).not.toBe('I am a spy'); expect(target.toString).not.toBe('I am a spy');
expect(subject.hasOwnProperty).not.toBe('I am a spy'); expect(target.hasOwnProperty).not.toBe('I am a spy');
}); });
describe('when includeNonEnumerable is true', function() { describe('when includeNonEnumerable is true', function() {
it('does not override Object.prototype methods', function() { it('does not override Object.prototype methods', function() {
@@ -438,15 +438,15 @@ describe('SpyRegistry', function() {
return 'I am a spy'; return 'I am a spy';
} }
}); });
const subject = { const target = {
spied1: function() {} spied1: function() {}
}; };
spyRegistry.spyOnAllFunctions(subject, true); spyRegistry.spyOnAllFunctions(target, true);
expect(subject.spied1).toBe('I am a spy'); expect(target.spied1).toBe('I am a spy');
expect(subject.toString).not.toBe('I am a spy'); expect(target.toString).not.toBe('I am a spy');
expect(subject.hasOwnProperty).not.toBe('I am a spy'); expect(target.hasOwnProperty).not.toBe('I am a spy');
}); });
it('overrides non-enumerable properties', function() { it('overrides non-enumerable properties', function() {
@@ -455,21 +455,21 @@ describe('SpyRegistry', function() {
return 'I am a spy'; return 'I am a spy';
} }
}); });
const subject = { const target = {
spied1: function() {}, spied1: function() {},
spied2: function() {} spied2: function() {}
}; };
Object.defineProperty(subject, 'spied2', { Object.defineProperty(target, 'spied2', {
enumerable: false, enumerable: false,
writable: true, writable: true,
configurable: true configurable: true
}); });
spyRegistry.spyOnAllFunctions(subject, true); spyRegistry.spyOnAllFunctions(target, true);
expect(subject.spied1).toBe('I am a spy'); expect(target.spied1).toBe('I am a spy');
expect(subject.spied2).toBe('I am a spy'); expect(target.spied2).toBe('I am a spy');
}); });
it('should not spy on non-enumerable functions named constructor', function() { it('should not spy on non-enumerable functions named constructor', function() {
@@ -478,19 +478,19 @@ describe('SpyRegistry', function() {
return 'I am a spy'; return 'I am a spy';
} }
}); });
const subject = { const target = {
constructor: function() {} constructor: function() {}
}; };
Object.defineProperty(subject, 'constructor', { Object.defineProperty(target, 'constructor', {
enumerable: false, enumerable: false,
writable: true, writable: true,
configurable: true configurable: true
}); });
spyRegistry.spyOnAllFunctions(subject, true); spyRegistry.spyOnAllFunctions(target, true);
expect(subject.constructor).not.toBe('I am a spy'); expect(target.constructor).not.toBe('I am a spy');
}); });
it('should spy on enumerable functions named constructor', function() { it('should spy on enumerable functions named constructor', function() {
@@ -499,13 +499,13 @@ describe('SpyRegistry', function() {
return 'I am a spy'; return 'I am a spy';
} }
}); });
const subject = { const target = {
constructor: function() {} constructor: function() {}
}; };
spyRegistry.spyOnAllFunctions(subject, true); spyRegistry.spyOnAllFunctions(target, true);
expect(subject.constructor).toBe('I am a spy'); expect(target.constructor).toBe('I am a spy');
}); });
it('should not throw an exception if we try and access strict mode restricted properties', function() { it('should not throw an exception if we try and access strict mode restricted properties', function() {
@@ -514,9 +514,9 @@ describe('SpyRegistry', function() {
return 'I am a spy'; return 'I am a spy';
} }
}); });
const subject = function() {}; const target = function() {};
const fn = function() { const fn = function() {
spyRegistry.spyOnAllFunctions(subject, true); spyRegistry.spyOnAllFunctions(target, true);
}; };
expect(fn).not.toThrow(); expect(fn).not.toThrow();
@@ -528,24 +528,24 @@ describe('SpyRegistry', function() {
return 'I am a spy'; return 'I am a spy';
} }
}); });
const subjectParent = Object.defineProperty({}, 'sharedProp', { const targetParent = Object.defineProperty({}, 'sharedProp', {
value: function() {}, value: function() {},
writable: true, writable: true,
configurable: true configurable: true
}); });
const subject = Object.create(subjectParent); const target = Object.create(targetParent);
Object.defineProperty(subject, 'sharedProp', { Object.defineProperty(target, 'sharedProp', {
value: function() {} value: function() {}
}); });
const fn = function() { const fn = function() {
spyRegistry.spyOnAllFunctions(subject, true); spyRegistry.spyOnAllFunctions(target, true);
}; };
expect(fn).not.toThrow(); expect(fn).not.toThrow();
expect(subject).not.toBe('I am a spy'); expect(target).not.toBe('I am a spy');
}); });
}); });
}); });
@@ -560,12 +560,12 @@ describe('SpyRegistry', function() {
createSpy: createSpy createSpy: createSpy
}), }),
originalFunction = function() {}, originalFunction = function() {},
subject = { spiedFunc: originalFunction }; target = { spiedFunc: originalFunction };
spyRegistry.spyOn(subject, 'spiedFunc'); spyRegistry.spyOn(target, 'spiedFunc');
spyRegistry.clearSpies(); spyRegistry.clearSpies();
expect(subject.spiedFunc).toBe(originalFunction); expect(target.spiedFunc).toBe(originalFunction);
}); });
it('restores the original functions, even when that spy has been replace and re-spied upon', function() { it('restores the original functions, even when that spy has been replace and re-spied upon', function() {
@@ -577,19 +577,19 @@ describe('SpyRegistry', function() {
createSpy: createSpy createSpy: createSpy
}), }),
originalFunction = function() {}, originalFunction = function() {},
subject = { spiedFunc: originalFunction }; target = { spiedFunc: originalFunction };
spyRegistry.spyOn(subject, 'spiedFunc'); spyRegistry.spyOn(target, 'spiedFunc');
// replace the original spy with some other function // replace the original spy with some other function
subject.spiedFunc = function() {}; target.spiedFunc = function() {};
// spy on the function in that location again // spy on the function in that location again
spyRegistry.spyOn(subject, 'spiedFunc'); spyRegistry.spyOn(target, 'spiedFunc');
spyRegistry.clearSpies(); spyRegistry.clearSpies();
expect(subject.spiedFunc).toBe(originalFunction); expect(target.spiedFunc).toBe(originalFunction);
}); });
it("does not add a property that the spied-upon object didn't originally have", function() { it("does not add a property that the spied-upon object didn't originally have", function() {
@@ -601,17 +601,17 @@ describe('SpyRegistry', function() {
createSpy: createSpy createSpy: createSpy
}), }),
originalFunction = function() {}, originalFunction = function() {},
subjectParent = { spiedFunc: originalFunction }; targetParent = { spiedFunc: originalFunction };
const subject = Object.create(subjectParent); const target = Object.create(targetParent);
expect(subject.hasOwnProperty('spiedFunc')).toBe(false); expect(target.hasOwnProperty('spiedFunc')).toBe(false);
spyRegistry.spyOn(subject, 'spiedFunc'); spyRegistry.spyOn(target, 'spiedFunc');
spyRegistry.clearSpies(); spyRegistry.clearSpies();
expect(subject.hasOwnProperty('spiedFunc')).toBe(false); expect(target.hasOwnProperty('spiedFunc')).toBe(false);
expect(subject.spiedFunc).toBe(originalFunction); expect(target.spiedFunc).toBe(originalFunction);
}); });
it("restores the original function when it's inherited and cannot be deleted", function() { it("restores the original function when it's inherited and cannot be deleted", function() {
@@ -623,20 +623,20 @@ describe('SpyRegistry', function() {
createSpy: createSpy createSpy: createSpy
}), }),
originalFunction = function() {}, originalFunction = function() {},
subjectParent = { spiedFunc: originalFunction }; targetParent = { spiedFunc: originalFunction };
const subject = Object.create(subjectParent); const target = Object.create(targetParent);
spyRegistry.spyOn(subject, 'spiedFunc'); spyRegistry.spyOn(target, 'spiedFunc');
// simulate a spy that cannot be deleted // simulate a spy that cannot be deleted
Object.defineProperty(subject, 'spiedFunc', { Object.defineProperty(target, 'spiedFunc', {
configurable: false configurable: false
}); });
spyRegistry.clearSpies(); spyRegistry.clearSpies();
expect(jasmineUnderTest.isSpy(subject.spiedFunc)).toBe(false); expect(jasmineUnderTest.isSpy(target.spiedFunc)).toBe(false);
}); });
it('restores window.onerror by overwriting, not deleting', function() { it('restores window.onerror by overwriting, not deleting', function() {
@@ -670,19 +670,19 @@ describe('SpyRegistry', function() {
createSpy: createSpy createSpy: createSpy
}), }),
originalReturn = 1, originalReturn = 1,
subject = {}; target = {};
Object.defineProperty(subject, 'spiedProp', { Object.defineProperty(target, 'spiedProp', {
get: function() { get: function() {
return originalReturn; return originalReturn;
}, },
configurable: true configurable: true
}); });
spyRegistry.spyOnProperty(subject, 'spiedProp'); spyRegistry.spyOnProperty(target, 'spiedProp');
spyRegistry.clearSpies(); spyRegistry.clearSpies();
expect(subject.spiedProp).toBe(originalReturn); expect(target.spiedProp).toBe(originalReturn);
}); });
it("does not add a property that the spied-upon object didn't originally have", function() { it("does not add a property that the spied-upon object didn't originally have", function() {
@@ -694,24 +694,24 @@ describe('SpyRegistry', function() {
createSpy: createSpy createSpy: createSpy
}), }),
originalReturn = 1, originalReturn = 1,
subjectParent = {}; targetParent = {};
Object.defineProperty(subjectParent, 'spiedProp', { Object.defineProperty(targetParent, 'spiedProp', {
get: function() { get: function() {
return originalReturn; return originalReturn;
}, },
configurable: true configurable: true
}); });
const subject = Object.create(subjectParent); const target = Object.create(targetParent);
expect(subject.hasOwnProperty('spiedProp')).toBe(false); expect(target.hasOwnProperty('spiedProp')).toBe(false);
spyRegistry.spyOnProperty(subject, 'spiedProp'); spyRegistry.spyOnProperty(target, 'spiedProp');
spyRegistry.clearSpies(); spyRegistry.clearSpies();
expect(subject.hasOwnProperty('spiedProp')).toBe(false); expect(target.hasOwnProperty('spiedProp')).toBe(false);
expect(subject.spiedProp).toBe(originalReturn); expect(target.spiedProp).toBe(originalReturn);
}); });
}); });
}); });