Moved createSpy to env so it can be stateful
This commit is contained in:
@@ -305,18 +305,6 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
return new j$.ArrayWithExactContents(sample);
|
return new j$.ArrayWithExactContents(sample);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a bare {@link Spy} object. This won't be installed anywhere and will not have any implementation behind it.
|
|
||||||
* @name jasmine.createSpy
|
|
||||||
* @function
|
|
||||||
* @param {String} [name] - Name to give the spy. This will be displayed in failure messages.
|
|
||||||
* @param {Function} [originalFn] - Function to act as the real implementation.
|
|
||||||
* @return {Spy}
|
|
||||||
*/
|
|
||||||
j$.createSpy = function(name, originalFn) {
|
|
||||||
return j$.Spy(name, originalFn);
|
|
||||||
};
|
|
||||||
|
|
||||||
j$.isSpy = function(putativeSpy) {
|
j$.isSpy = function(putativeSpy) {
|
||||||
if (!putativeSpy) {
|
if (!putativeSpy) {
|
||||||
return false;
|
return false;
|
||||||
@@ -1093,12 +1081,17 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
reporter.clearReporters();
|
reporter.clearReporters();
|
||||||
};
|
};
|
||||||
|
|
||||||
var spyRegistry = new j$.SpyRegistry({currentSpies: function() {
|
var spyRegistry = new j$.SpyRegistry({
|
||||||
if(!currentRunnable()) {
|
currentSpies: function() {
|
||||||
throw new Error('Spies must be created in a before function or a spec');
|
if(!currentRunnable()) {
|
||||||
|
throw new Error('Spies must be created in a before function or a spec');
|
||||||
|
}
|
||||||
|
return runnableResources[currentRunnable().id].spies;
|
||||||
|
},
|
||||||
|
createSpy: function(name, originalFn) {
|
||||||
|
return self.createSpy(name, originalFn);
|
||||||
}
|
}
|
||||||
return runnableResources[currentRunnable().id].spies;
|
});
|
||||||
}});
|
|
||||||
|
|
||||||
this.allowRespy = function(allow){
|
this.allowRespy = function(allow){
|
||||||
spyRegistry.allowRespy(allow);
|
spyRegistry.allowRespy(allow);
|
||||||
@@ -1112,6 +1105,10 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
return spyRegistry.spyOnProperty.apply(spyRegistry, arguments);
|
return spyRegistry.spyOnProperty.apply(spyRegistry, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.createSpy = function(name, originalFn) {
|
||||||
|
return j$.Spy(name, originalFn);
|
||||||
|
};
|
||||||
|
|
||||||
this.createSpyObj = function(baseName, methodNames) {
|
this.createSpyObj = function(baseName, methodNames) {
|
||||||
var baseNameIsCollection = j$.isObject_(baseName) || j$.isArray_(baseName);
|
var baseNameIsCollection = j$.isObject_(baseName) || j$.isArray_(baseName);
|
||||||
|
|
||||||
@@ -1125,13 +1122,13 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
|
|
||||||
if (j$.isArray_(methodNames)) {
|
if (j$.isArray_(methodNames)) {
|
||||||
for (var i = 0; i < methodNames.length; i++) {
|
for (var i = 0; i < methodNames.length; i++) {
|
||||||
obj[methodNames[i]] = j$.createSpy(baseName + '.' + methodNames[i]);
|
obj[methodNames[i]] = self.createSpy(baseName + '.' + methodNames[i]);
|
||||||
spiesWereSet = true;
|
spiesWereSet = true;
|
||||||
}
|
}
|
||||||
} else if (j$.isObject_(methodNames)) {
|
} else if (j$.isObject_(methodNames)) {
|
||||||
for (var key in methodNames) {
|
for (var key in methodNames) {
|
||||||
if (methodNames.hasOwnProperty(key)) {
|
if (methodNames.hasOwnProperty(key)) {
|
||||||
obj[key] = j$.createSpy(baseName + '.' + key);
|
obj[key] = self.createSpy(baseName + '.' + key);
|
||||||
obj[key].and.returnValue(methodNames[key]);
|
obj[key].and.returnValue(methodNames[key]);
|
||||||
spiesWereSet = true;
|
spiesWereSet = true;
|
||||||
}
|
}
|
||||||
@@ -4906,6 +4903,18 @@ getJasmineRequireObj().interface = function(jasmine, env) {
|
|||||||
return env.clock;
|
return env.clock;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a bare {@link Spy} object. This won't be installed anywhere and will not have any implementation behind it.
|
||||||
|
* @name jasmine.createSpy
|
||||||
|
* @function
|
||||||
|
* @param {String} [name] - Name to give the spy. This will be displayed in failure messages.
|
||||||
|
* @param {Function} [originalFn] - Function to act as the real implementation.
|
||||||
|
* @return {Spy}
|
||||||
|
*/
|
||||||
|
jasmine.createSpy = function(name, originalFn) {
|
||||||
|
return env.createSpy(name, originalFn);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an object with multiple {@link Spy}s as its members.
|
* Create an object with multiple {@link Spy}s as its members.
|
||||||
* @name jasmine.createSpyObj
|
* @name jasmine.createSpyObj
|
||||||
@@ -5090,6 +5099,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
|
|
||||||
function SpyRegistry(options) {
|
function SpyRegistry(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
var createSpy = options.createSpy;
|
||||||
var currentSpies = options.currentSpies || function() { return []; };
|
var currentSpies = options.currentSpies || function() { return []; };
|
||||||
|
|
||||||
this.allowRespy = function(allow){
|
this.allowRespy = function(allow){
|
||||||
@@ -5125,7 +5135,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var originalMethod = obj[methodName],
|
var originalMethod = obj[methodName],
|
||||||
spiedMethod = j$.createSpy(methodName, originalMethod),
|
spiedMethod = createSpy(methodName, originalMethod),
|
||||||
restoreStrategy;
|
restoreStrategy;
|
||||||
|
|
||||||
if (Object.prototype.hasOwnProperty.call(obj, methodName)) {
|
if (Object.prototype.hasOwnProperty.call(obj, methodName)) {
|
||||||
@@ -5180,7 +5190,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var originalDescriptor = j$.util.clone(descriptor),
|
var originalDescriptor = j$.util.clone(descriptor),
|
||||||
spy = j$.createSpy(propertyName, descriptor[accessType]),
|
spy = createSpy(propertyName, descriptor[accessType]),
|
||||||
restoreStrategy;
|
restoreStrategy;
|
||||||
|
|
||||||
if (Object.prototype.hasOwnProperty.call(obj, propertyName)) {
|
if (Object.prototype.hasOwnProperty.call(obj, propertyName)) {
|
||||||
|
|||||||
@@ -255,12 +255,17 @@ describe("jasmineUnderTest.pp", function () {
|
|||||||
},
|
},
|
||||||
env = new jasmineUnderTest.Env();
|
env = new jasmineUnderTest.Env();
|
||||||
|
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() {return [];}});
|
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
|
currentSpies: function() {return [];},
|
||||||
|
createSpy: function(name, originalFn) {
|
||||||
|
return jasmineUnderTest.Spy(name, originalFn);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
spyRegistry.spyOn(TestObject, 'someFunction');
|
spyRegistry.spyOn(TestObject, 'someFunction');
|
||||||
expect(jasmineUnderTest.pp(TestObject.someFunction)).toEqual("spy on someFunction");
|
expect(jasmineUnderTest.pp(TestObject.someFunction)).toEqual("spy on someFunction");
|
||||||
|
|
||||||
expect(jasmineUnderTest.pp(jasmineUnderTest.createSpy("something"))).toEqual("spy on something");
|
expect(jasmineUnderTest.pp(env.createSpy("something"))).toEqual("spy on something");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should stringify objects that implement jasmineToString", function () {
|
it("should stringify objects that implement jasmineToString", function () {
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
describe("SpyRegistry", function() {
|
describe("SpyRegistry", function() {
|
||||||
|
function createSpy(name, originalFn) {
|
||||||
|
return jasmineUnderTest.Spy(name, originalFn);
|
||||||
|
}
|
||||||
|
|
||||||
describe("#spyOn", function() {
|
describe("#spyOn", function() {
|
||||||
it("checks for the existence of the object", function() {
|
it("checks for the existence of the object", function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry();
|
var spyRegistry = new jasmineUnderTest.SpyRegistry({createSpy: createSpy});
|
||||||
expect(function() {
|
expect(function() {
|
||||||
spyRegistry.spyOn(void 0, 'pants');
|
spyRegistry.spyOn(void 0, 'pants');
|
||||||
}).toThrowError(/could not find an object/);
|
}).toThrowError(/could not find an object/);
|
||||||
@@ -43,7 +47,10 @@ describe("SpyRegistry", function() {
|
|||||||
|
|
||||||
it("checks if it has already been spied upon", function() {
|
it("checks if it has already been spied upon", function() {
|
||||||
var spies = [],
|
var spies = [],
|
||||||
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
|
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
|
currentSpies: function() { return spies; },
|
||||||
|
createSpy: createSpy
|
||||||
|
}),
|
||||||
subject = { spiedFunc: function() {} };
|
subject = { spiedFunc: function() {} };
|
||||||
|
|
||||||
spyRegistry.spyOn(subject, 'spiedFunc');
|
spyRegistry.spyOn(subject, 'spiedFunc');
|
||||||
@@ -81,7 +88,7 @@ describe("SpyRegistry", function() {
|
|||||||
|
|
||||||
it("overrides the method on the object and returns the spy", function() {
|
it("overrides the method on the object and returns the spy", function() {
|
||||||
var originalFunctionWasCalled = false,
|
var originalFunctionWasCalled = false,
|
||||||
spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
spyRegistry = new jasmineUnderTest.SpyRegistry({createSpy: createSpy}),
|
||||||
subject = { spiedFunc: function() { originalFunctionWasCalled = true; } };
|
subject = { spiedFunc: function() { originalFunctionWasCalled = true; } };
|
||||||
|
|
||||||
var spy = spyRegistry.spyOn(subject, 'spiedFunc');
|
var spy = spyRegistry.spyOn(subject, 'spiedFunc');
|
||||||
@@ -131,7 +138,7 @@ describe("SpyRegistry", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("checks if it has already been spied upon", function() {
|
it("checks if it has already been spied upon", function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
var spyRegistry = new jasmineUnderTest.SpyRegistry({createSpy: createSpy}),
|
||||||
subject = {};
|
subject = {};
|
||||||
|
|
||||||
Object.defineProperty(subject, 'spiedProp', {
|
Object.defineProperty(subject, 'spiedProp', {
|
||||||
@@ -170,7 +177,7 @@ describe("SpyRegistry", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("overrides the property getter on the object and returns the spy", function() {
|
it("overrides the property getter on the object and returns the spy", function() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
var spyRegistry = new jasmineUnderTest.SpyRegistry({createSpy: createSpy}),
|
||||||
subject = {},
|
subject = {},
|
||||||
returnValue = 1;
|
returnValue = 1;
|
||||||
|
|
||||||
@@ -189,7 +196,7 @@ describe("SpyRegistry", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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() {
|
||||||
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
var spyRegistry = new jasmineUnderTest.SpyRegistry({createSpy: createSpy}),
|
||||||
subject = {},
|
subject = {},
|
||||||
returnValue = 1;
|
returnValue = 1;
|
||||||
|
|
||||||
@@ -210,7 +217,10 @@ describe("SpyRegistry", function() {
|
|||||||
describe("#clearSpies", function() {
|
describe("#clearSpies", function() {
|
||||||
it("restores the original functions on the spied-upon objects", function() {
|
it("restores the original functions on the spied-upon objects", function() {
|
||||||
var spies = [],
|
var spies = [],
|
||||||
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
|
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
|
currentSpies: function() { return spies; },
|
||||||
|
createSpy: createSpy
|
||||||
|
}),
|
||||||
originalFunction = function() {},
|
originalFunction = function() {},
|
||||||
subject = { spiedFunc: originalFunction };
|
subject = { spiedFunc: originalFunction };
|
||||||
|
|
||||||
@@ -222,7 +232,10 @@ describe("SpyRegistry", function() {
|
|||||||
|
|
||||||
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() {
|
||||||
var spies = [],
|
var spies = [],
|
||||||
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
|
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
|
currentSpies: function() { return spies; },
|
||||||
|
createSpy: createSpy
|
||||||
|
}),
|
||||||
originalFunction = function() {},
|
originalFunction = function() {},
|
||||||
subject = { spiedFunc: originalFunction };
|
subject = { spiedFunc: originalFunction };
|
||||||
|
|
||||||
@@ -241,7 +254,10 @@ describe("SpyRegistry", function() {
|
|||||||
|
|
||||||
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() {
|
||||||
var spies = [],
|
var spies = [],
|
||||||
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
|
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
|
currentSpies: function() { return spies; },
|
||||||
|
createSpy: createSpy
|
||||||
|
}),
|
||||||
originalFunction = function() {},
|
originalFunction = function() {},
|
||||||
subjectParent = {spiedFunc: originalFunction};
|
subjectParent = {spiedFunc: originalFunction};
|
||||||
|
|
||||||
@@ -258,7 +274,10 @@ describe("SpyRegistry", function() {
|
|||||||
|
|
||||||
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() {
|
||||||
var spies = [],
|
var spies = [],
|
||||||
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
|
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
|
currentSpies: function() { return spies; },
|
||||||
|
createSpy: createSpy
|
||||||
|
}),
|
||||||
originalFunction = function() {},
|
originalFunction = function() {},
|
||||||
subjectParent = {spiedFunc: originalFunction};
|
subjectParent = {spiedFunc: originalFunction};
|
||||||
|
|
||||||
@@ -280,7 +299,10 @@ describe("SpyRegistry", function() {
|
|||||||
describe('spying on properties', function() {
|
describe('spying on properties', function() {
|
||||||
it("restores the original properties on the spied-upon objects", function() {
|
it("restores the original properties on the spied-upon objects", function() {
|
||||||
var spies = [],
|
var spies = [],
|
||||||
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
|
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
|
currentSpies: function() { return spies; },
|
||||||
|
createSpy: createSpy
|
||||||
|
}),
|
||||||
originalReturn = 1,
|
originalReturn = 1,
|
||||||
subject = {};
|
subject = {};
|
||||||
|
|
||||||
@@ -297,7 +319,10 @@ describe("SpyRegistry", function() {
|
|||||||
|
|
||||||
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() {
|
||||||
var spies = [],
|
var spies = [],
|
||||||
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
|
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||||
|
currentSpies: function() { return spies; },
|
||||||
|
createSpy: createSpy
|
||||||
|
}),
|
||||||
originalReturn = 1,
|
originalReturn = 1,
|
||||||
subjectParent = {};
|
subjectParent = {};
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ describe('Spies', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("preserves the properties of the spied function", function() {
|
it("preserves the properties of the spied function", function() {
|
||||||
var spy = jasmineUnderTest.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
var spy = env.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
||||||
|
|
||||||
expect(spy.bob).toEqual("test");
|
expect(spy.bob).toEqual("test");
|
||||||
});
|
});
|
||||||
@@ -24,19 +24,19 @@ describe('Spies', function () {
|
|||||||
TestClass.prototype.someFunction.and = "turkey";
|
TestClass.prototype.someFunction.and = "turkey";
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
jasmineUnderTest.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
env.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
||||||
}).toThrowError("Jasmine spies would overwrite the 'and' and 'calls' properties on the object being spied upon");
|
}).toThrowError("Jasmine spies would overwrite the 'and' and 'calls' properties on the object being spied upon");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("adds a spyStrategy and callTracker to the spy", function() {
|
it("adds a spyStrategy and callTracker to the spy", function() {
|
||||||
var spy = jasmineUnderTest.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
var spy = env.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
||||||
|
|
||||||
expect(spy.and).toEqual(jasmine.any(jasmineUnderTest.SpyStrategy));
|
expect(spy.and).toEqual(jasmine.any(jasmineUnderTest.SpyStrategy));
|
||||||
expect(spy.calls).toEqual(jasmine.any(jasmineUnderTest.CallTracker));
|
expect(spy.calls).toEqual(jasmine.any(jasmineUnderTest.CallTracker));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("tracks the argument of calls", function () {
|
it("tracks the argument of calls", function () {
|
||||||
var spy = jasmineUnderTest.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
var spy = env.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
||||||
var trackSpy = spyOn(spy.calls, "track");
|
var trackSpy = spyOn(spy.calls, "track");
|
||||||
|
|
||||||
spy("arg");
|
spy("arg");
|
||||||
@@ -45,7 +45,7 @@ describe('Spies', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("tracks the context of calls", function () {
|
it("tracks the context of calls", function () {
|
||||||
var spy = jasmineUnderTest.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
var spy = env.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
||||||
var trackSpy = spyOn(spy.calls, "track");
|
var trackSpy = spyOn(spy.calls, "track");
|
||||||
|
|
||||||
var contextObject = { spyMethod: spy };
|
var contextObject = { spyMethod: spy };
|
||||||
@@ -55,7 +55,7 @@ describe('Spies', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("tracks the return value of calls", function () {
|
it("tracks the return value of calls", function () {
|
||||||
var spy = jasmineUnderTest.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
var spy = env.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
||||||
var trackSpy = spyOn(spy.calls, "track");
|
var trackSpy = spyOn(spy.calls, "track");
|
||||||
|
|
||||||
spy.and.returnValue("return value");
|
spy.and.returnValue("return value");
|
||||||
@@ -77,7 +77,7 @@ describe('Spies', function () {
|
|||||||
|
|
||||||
for (var arity = 0; arity < functions.length; arity++) {
|
for (var arity = 0; arity < functions.length; arity++) {
|
||||||
var someFunction = functions[arity],
|
var someFunction = functions[arity],
|
||||||
spy = jasmineUnderTest.createSpy(someFunction.name, someFunction);
|
spy = env.createSpy(someFunction.name, someFunction);
|
||||||
|
|
||||||
expect(spy.length).toEqual(arity);
|
expect(spy.length).toEqual(arity);
|
||||||
}
|
}
|
||||||
@@ -132,7 +132,7 @@ describe('Spies', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("can use different strategies for different arguments", function() {
|
it("can use different strategies for different arguments", function() {
|
||||||
var spy = jasmineUnderTest.createSpy('foo');
|
var spy = env.createSpy('foo');
|
||||||
spy.and.returnValue(42);
|
spy.and.returnValue(42);
|
||||||
spy.withArgs('baz', 'grault').and.returnValue(-1);
|
spy.withArgs('baz', 'grault').and.returnValue(-1);
|
||||||
spy.withArgs('thud').and.returnValue('bob');
|
spy.withArgs('thud').and.returnValue('bob');
|
||||||
@@ -144,7 +144,7 @@ describe('Spies', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("uses custom equality testers when selecting a strategy", function() {
|
it("uses custom equality testers when selecting a strategy", function() {
|
||||||
var spy = jasmineUnderTest.createSpy('foo');
|
var spy = env.createSpy('foo');
|
||||||
spy.and.returnValue(42);
|
spy.and.returnValue(42);
|
||||||
spy.withArgs(jasmineUnderTest.any(String)).and.returnValue(-1);
|
spy.withArgs(jasmineUnderTest.any(String)).and.returnValue(-1);
|
||||||
|
|
||||||
@@ -153,7 +153,7 @@ describe('Spies', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("can reconfigure an argument-specific strategy", function() {
|
it("can reconfigure an argument-specific strategy", function() {
|
||||||
var spy = jasmineUnderTest.createSpy('foo');
|
var spy = env.createSpy('foo');
|
||||||
spy.withArgs('foo').and.returnValue(42);
|
spy.withArgs('foo').and.returnValue(42);
|
||||||
spy.withArgs('foo').and.returnValue(17);
|
spy.withArgs('foo').and.returnValue(17);
|
||||||
expect(spy('foo')).toEqual(17);
|
expect(spy('foo')).toEqual(17);
|
||||||
@@ -161,14 +161,14 @@ describe('Spies', function () {
|
|||||||
|
|
||||||
describe("When withArgs is used without a base strategy", function() {
|
describe("When withArgs is used without a base strategy", function() {
|
||||||
it("uses the matching strategy", function() {
|
it("uses the matching strategy", function() {
|
||||||
var spy = jasmineUnderTest.createSpy('foo');
|
var spy = env.createSpy('foo');
|
||||||
spy.withArgs('baz').and.returnValue(-1);
|
spy.withArgs('baz').and.returnValue(-1);
|
||||||
|
|
||||||
expect(spy('baz')).toEqual(-1);
|
expect(spy('baz')).toEqual(-1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws if the args don't match", function() {
|
it("throws if the args don't match", function() {
|
||||||
var spy = jasmineUnderTest.createSpy('foo');
|
var spy = env.createSpy('foo');
|
||||||
spy.withArgs('bar').and.returnValue(-1);
|
spy.withArgs('bar').and.returnValue(-1);
|
||||||
|
|
||||||
expect(function() { spy('baz', {qux: 42}); }).toThrowError('Spy \'foo\' receieved a call with arguments [ \'baz\', Object({ qux: 42 }) ] but all configured strategies specify other arguments.');
|
expect(function() { spy('baz', {qux: 42}); }).toThrowError('Spy \'foo\' receieved a call with arguments [ \'baz\', Object({ qux: 42 }) ] but all configured strategies specify other arguments.');
|
||||||
|
|||||||
@@ -2,14 +2,14 @@ describe("toHaveBeenCalledBefore", function() {
|
|||||||
it("throws an exception when the actual is not a spy", function() {
|
it("throws an exception when the actual is not a spy", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||||
fn = function() {},
|
fn = function() {},
|
||||||
secondSpy = jasmineUnderTest.createSpy('second spy');
|
secondSpy = new jasmineUnderTest.Env().createSpy('second spy');
|
||||||
|
|
||||||
expect(function() { matcher.compare(fn, secondSpy) }).toThrowError(Error, /Expected a spy, but got Function./);
|
expect(function() { matcher.compare(fn, secondSpy) }).toThrowError(Error, /Expected a spy, but got Function./);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws an exception when the expected is not a spy", function() {
|
it("throws an exception when the expected is not a spy", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||||
firstSpy = jasmineUnderTest.createSpy('first spy'),
|
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'),
|
||||||
fn = function() {};
|
fn = function() {};
|
||||||
|
|
||||||
expect(function() { matcher.compare(firstSpy, fn) }).toThrowError(Error, /Expected a spy, but got Function./);
|
expect(function() { matcher.compare(firstSpy, fn) }).toThrowError(Error, /Expected a spy, but got Function./);
|
||||||
@@ -17,8 +17,8 @@ describe("toHaveBeenCalledBefore", function() {
|
|||||||
|
|
||||||
it("fails when the actual was not called", function() {
|
it("fails when the actual was not called", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||||
firstSpy = jasmineUnderTest.createSpy('first spy'),
|
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'),
|
||||||
secondSpy = jasmineUnderTest.createSpy('second spy');
|
secondSpy = new jasmineUnderTest.Env().createSpy('second spy');
|
||||||
|
|
||||||
secondSpy();
|
secondSpy();
|
||||||
|
|
||||||
@@ -29,8 +29,8 @@ describe("toHaveBeenCalledBefore", function() {
|
|||||||
|
|
||||||
it("fails when the expected was not called", function() {
|
it("fails when the expected was not called", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||||
firstSpy = jasmineUnderTest.createSpy('first spy'),
|
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'),
|
||||||
secondSpy = jasmineUnderTest.createSpy('second spy');
|
secondSpy = new jasmineUnderTest.Env().createSpy('second spy');
|
||||||
|
|
||||||
firstSpy();
|
firstSpy();
|
||||||
|
|
||||||
@@ -41,8 +41,8 @@ describe("toHaveBeenCalledBefore", function() {
|
|||||||
|
|
||||||
it("fails when the actual is called after the expected", function() {
|
it("fails when the actual is called after the expected", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||||
firstSpy = jasmineUnderTest.createSpy('first spy'),
|
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'),
|
||||||
secondSpy = jasmineUnderTest.createSpy('second spy'),
|
secondSpy = new jasmineUnderTest.Env().createSpy('second spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
secondSpy();
|
secondSpy();
|
||||||
@@ -55,8 +55,8 @@ describe("toHaveBeenCalledBefore", function() {
|
|||||||
|
|
||||||
it("fails when the actual is called before and after the expected", function() {
|
it("fails when the actual is called before and after the expected", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||||
firstSpy = jasmineUnderTest.createSpy('first spy'),
|
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'),
|
||||||
secondSpy = jasmineUnderTest.createSpy('second spy'),
|
secondSpy = new jasmineUnderTest.Env().createSpy('second spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
firstSpy();
|
firstSpy();
|
||||||
@@ -70,8 +70,8 @@ describe("toHaveBeenCalledBefore", function() {
|
|||||||
|
|
||||||
it("fails when the expected is called before and after the actual", function() {
|
it("fails when the expected is called before and after the actual", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||||
firstSpy = jasmineUnderTest.createSpy('first spy'),
|
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'),
|
||||||
secondSpy = jasmineUnderTest.createSpy('second spy'),
|
secondSpy = new jasmineUnderTest.Env().createSpy('second spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
secondSpy();
|
secondSpy();
|
||||||
@@ -85,8 +85,8 @@ describe("toHaveBeenCalledBefore", function() {
|
|||||||
|
|
||||||
it("passes when the actual is called before the expected", function() {
|
it("passes when the actual is called before the expected", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||||
firstSpy = jasmineUnderTest.createSpy('first spy'),
|
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'),
|
||||||
secondSpy = jasmineUnderTest.createSpy('second spy'),
|
secondSpy = new jasmineUnderTest.Env().createSpy('second spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
firstSpy();
|
firstSpy();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
describe("toHaveBeenCalled", function() {
|
describe("toHaveBeenCalled", function() {
|
||||||
it("passes when the actual was called, with a custom .not fail message", function() {
|
it("passes when the actual was called, with a custom .not fail message", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
||||||
calledSpy = jasmineUnderTest.createSpy('called-spy'),
|
calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
calledSpy();
|
calledSpy();
|
||||||
@@ -13,7 +13,7 @@ describe("toHaveBeenCalled", function() {
|
|||||||
|
|
||||||
it("fails when the actual was not called", function() {
|
it("fails when the actual was not called", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
||||||
uncalledSpy = jasmineUnderTest.createSpy('uncalled spy'),
|
uncalledSpy = new jasmineUnderTest.Env().createSpy('uncalled spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(uncalledSpy);
|
result = matcher.compare(uncalledSpy);
|
||||||
@@ -29,14 +29,14 @@ describe("toHaveBeenCalled", function() {
|
|||||||
|
|
||||||
it("throws an exception when invoked with any arguments", function() {
|
it("throws an exception when invoked with any arguments", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
||||||
spy = jasmineUnderTest.createSpy('sample spy');
|
spy = new jasmineUnderTest.Env().createSpy('sample spy');
|
||||||
|
|
||||||
expect(function() { matcher.compare(spy, 'foo') }).toThrowError(Error, /Does not take arguments, use toHaveBeenCalledWith/);
|
expect(function() { matcher.compare(spy, 'foo') }).toThrowError(Error, /Does not take arguments, use toHaveBeenCalledWith/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("has a custom message on failure", function() {
|
it("has a custom message on failure", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
||||||
spy = jasmineUnderTest.createSpy('sample-spy'),
|
spy = new jasmineUnderTest.Env().createSpy('sample-spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(spy);
|
result = matcher.compare(spy);
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
describe("toHaveBeenCalledTimes", function() {
|
describe("toHaveBeenCalledTimes", function() {
|
||||||
it("passes when the actual 0 matches the expected 0 ", function () {
|
it("passes when the actual 0 matches the expected 0 ", function () {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
calledSpy = jasmineUnderTest.createSpy('called-spy'),
|
calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'),
|
||||||
result;
|
result;
|
||||||
result = matcher.compare(calledSpy, 0);
|
result = matcher.compare(calledSpy, 0);
|
||||||
expect(result.pass).toBeTruthy();
|
expect(result.pass).toBeTruthy();
|
||||||
});
|
});
|
||||||
it("passes when the actual matches the expected", function() {
|
it("passes when the actual matches the expected", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
calledSpy = jasmineUnderTest.createSpy('called-spy'),
|
calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'),
|
||||||
result;
|
result;
|
||||||
calledSpy();
|
calledSpy();
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ describe("toHaveBeenCalledTimes", function() {
|
|||||||
|
|
||||||
it("fails when expected numbers is not supplied", function(){
|
it("fails when expected numbers is not supplied", function(){
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
spy = jasmineUnderTest.createSpy('spy'),
|
spy = new jasmineUnderTest.Env().createSpy('spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
spy();
|
spy();
|
||||||
@@ -29,7 +29,7 @@ describe("toHaveBeenCalledTimes", function() {
|
|||||||
|
|
||||||
it("fails when the actual was called less than the expected", function() {
|
it("fails when the actual was called less than the expected", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
uncalledSpy = jasmineUnderTest.createSpy('uncalled spy'),
|
uncalledSpy = new jasmineUnderTest.Env().createSpy('uncalled spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(uncalledSpy, 2);
|
result = matcher.compare(uncalledSpy, 2);
|
||||||
@@ -38,7 +38,7 @@ describe("toHaveBeenCalledTimes", function() {
|
|||||||
|
|
||||||
it("fails when the actual was called more than expected", function() {
|
it("fails when the actual was called more than expected", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
uncalledSpy = jasmineUnderTest.createSpy('uncalled spy'),
|
uncalledSpy = new jasmineUnderTest.Env().createSpy('uncalled spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
uncalledSpy();
|
uncalledSpy();
|
||||||
@@ -59,7 +59,7 @@ describe("toHaveBeenCalledTimes", function() {
|
|||||||
|
|
||||||
it("has a custom message on failure that tells it was called only once", function() {
|
it("has a custom message on failure that tells it was called only once", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
spy = jasmineUnderTest.createSpy('sample-spy'),
|
spy = new jasmineUnderTest.Env().createSpy('sample-spy'),
|
||||||
result;
|
result;
|
||||||
spy();
|
spy();
|
||||||
spy();
|
spy();
|
||||||
@@ -72,7 +72,7 @@ describe("toHaveBeenCalledTimes", function() {
|
|||||||
|
|
||||||
it("has a custom message on failure that tells how many times it was called", function() {
|
it("has a custom message on failure that tells how many times it was called", function() {
|
||||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||||
spy = jasmineUnderTest.createSpy('sample-spy'),
|
spy = new jasmineUnderTest.Env().createSpy('sample-spy'),
|
||||||
result;
|
result;
|
||||||
spy();
|
spy();
|
||||||
spy();
|
spy();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ describe("toHaveBeenCalledWith", function() {
|
|||||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
|
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
||||||
calledSpy = jasmineUnderTest.createSpy('called-spy'),
|
calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
calledSpy('a', 'b');
|
calledSpy('a', 'b');
|
||||||
@@ -21,7 +21,7 @@ describe("toHaveBeenCalledWith", function() {
|
|||||||
},
|
},
|
||||||
customEqualityTesters = [function() { return true; }],
|
customEqualityTesters = [function() { return true; }],
|
||||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util, customEqualityTesters),
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util, customEqualityTesters),
|
||||||
calledSpy = jasmineUnderTest.createSpy('called-spy');
|
calledSpy = new jasmineUnderTest.Env().createSpy('called-spy');
|
||||||
|
|
||||||
calledSpy('a', 'b');
|
calledSpy('a', 'b');
|
||||||
matcher.compare(calledSpy, 'a', 'b');
|
matcher.compare(calledSpy, 'a', 'b');
|
||||||
@@ -34,7 +34,7 @@ describe("toHaveBeenCalledWith", function() {
|
|||||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
|
contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
||||||
uncalledSpy = jasmineUnderTest.createSpy('uncalled spy'),
|
uncalledSpy = new jasmineUnderTest.Env().createSpy('uncalled spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
result = matcher.compare(uncalledSpy);
|
result = matcher.compare(uncalledSpy);
|
||||||
@@ -47,7 +47,7 @@ describe("toHaveBeenCalledWith", function() {
|
|||||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
|
contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
|
||||||
},
|
},
|
||||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
||||||
calledSpy = jasmineUnderTest.createSpy('called spy'),
|
calledSpy = new jasmineUnderTest.Env().createSpy('called spy'),
|
||||||
result;
|
result;
|
||||||
|
|
||||||
calledSpy('a');
|
calledSpy('a');
|
||||||
|
|||||||
@@ -393,12 +393,17 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
reporter.clearReporters();
|
reporter.clearReporters();
|
||||||
};
|
};
|
||||||
|
|
||||||
var spyRegistry = new j$.SpyRegistry({currentSpies: function() {
|
var spyRegistry = new j$.SpyRegistry({
|
||||||
if(!currentRunnable()) {
|
currentSpies: function() {
|
||||||
throw new Error('Spies must be created in a before function or a spec');
|
if(!currentRunnable()) {
|
||||||
|
throw new Error('Spies must be created in a before function or a spec');
|
||||||
|
}
|
||||||
|
return runnableResources[currentRunnable().id].spies;
|
||||||
|
},
|
||||||
|
createSpy: function(name, originalFn) {
|
||||||
|
return self.createSpy(name, originalFn);
|
||||||
}
|
}
|
||||||
return runnableResources[currentRunnable().id].spies;
|
});
|
||||||
}});
|
|
||||||
|
|
||||||
this.allowRespy = function(allow){
|
this.allowRespy = function(allow){
|
||||||
spyRegistry.allowRespy(allow);
|
spyRegistry.allowRespy(allow);
|
||||||
@@ -412,6 +417,10 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
return spyRegistry.spyOnProperty.apply(spyRegistry, arguments);
|
return spyRegistry.spyOnProperty.apply(spyRegistry, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.createSpy = function(name, originalFn) {
|
||||||
|
return j$.Spy(name, originalFn);
|
||||||
|
};
|
||||||
|
|
||||||
this.createSpyObj = function(baseName, methodNames) {
|
this.createSpyObj = function(baseName, methodNames) {
|
||||||
var baseNameIsCollection = j$.isObject_(baseName) || j$.isArray_(baseName);
|
var baseNameIsCollection = j$.isObject_(baseName) || j$.isArray_(baseName);
|
||||||
|
|
||||||
@@ -425,13 +434,13 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
|
|
||||||
if (j$.isArray_(methodNames)) {
|
if (j$.isArray_(methodNames)) {
|
||||||
for (var i = 0; i < methodNames.length; i++) {
|
for (var i = 0; i < methodNames.length; i++) {
|
||||||
obj[methodNames[i]] = j$.createSpy(baseName + '.' + methodNames[i]);
|
obj[methodNames[i]] = self.createSpy(baseName + '.' + methodNames[i]);
|
||||||
spiesWereSet = true;
|
spiesWereSet = true;
|
||||||
}
|
}
|
||||||
} else if (j$.isObject_(methodNames)) {
|
} else if (j$.isObject_(methodNames)) {
|
||||||
for (var key in methodNames) {
|
for (var key in methodNames) {
|
||||||
if (methodNames.hasOwnProperty(key)) {
|
if (methodNames.hasOwnProperty(key)) {
|
||||||
obj[key] = j$.createSpy(baseName + '.' + key);
|
obj[key] = self.createSpy(baseName + '.' + key);
|
||||||
obj[key].and.returnValue(methodNames[key]);
|
obj[key].and.returnValue(methodNames[key]);
|
||||||
spiesWereSet = true;
|
spiesWereSet = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
|
|
||||||
function SpyRegistry(options) {
|
function SpyRegistry(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
var createSpy = options.createSpy;
|
||||||
var currentSpies = options.currentSpies || function() { return []; };
|
var currentSpies = options.currentSpies || function() { return []; };
|
||||||
|
|
||||||
this.allowRespy = function(allow){
|
this.allowRespy = function(allow){
|
||||||
@@ -39,7 +40,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var originalMethod = obj[methodName],
|
var originalMethod = obj[methodName],
|
||||||
spiedMethod = j$.createSpy(methodName, originalMethod),
|
spiedMethod = createSpy(methodName, originalMethod),
|
||||||
restoreStrategy;
|
restoreStrategy;
|
||||||
|
|
||||||
if (Object.prototype.hasOwnProperty.call(obj, methodName)) {
|
if (Object.prototype.hasOwnProperty.call(obj, methodName)) {
|
||||||
@@ -94,7 +95,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var originalDescriptor = j$.util.clone(descriptor),
|
var originalDescriptor = j$.util.clone(descriptor),
|
||||||
spy = j$.createSpy(propertyName, descriptor[accessType]),
|
spy = createSpy(propertyName, descriptor[accessType]),
|
||||||
restoreStrategy;
|
restoreStrategy;
|
||||||
|
|
||||||
if (Object.prototype.hasOwnProperty.call(obj, propertyName)) {
|
if (Object.prototype.hasOwnProperty.call(obj, propertyName)) {
|
||||||
|
|||||||
@@ -173,18 +173,6 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
return new j$.ArrayWithExactContents(sample);
|
return new j$.ArrayWithExactContents(sample);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a bare {@link Spy} object. This won't be installed anywhere and will not have any implementation behind it.
|
|
||||||
* @name jasmine.createSpy
|
|
||||||
* @function
|
|
||||||
* @param {String} [name] - Name to give the spy. This will be displayed in failure messages.
|
|
||||||
* @param {Function} [originalFn] - Function to act as the real implementation.
|
|
||||||
* @return {Spy}
|
|
||||||
*/
|
|
||||||
j$.createSpy = function(name, originalFn) {
|
|
||||||
return j$.Spy(name, originalFn);
|
|
||||||
};
|
|
||||||
|
|
||||||
j$.isSpy = function(putativeSpy) {
|
j$.isSpy = function(putativeSpy) {
|
||||||
if (!putativeSpy) {
|
if (!putativeSpy) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -256,6 +256,18 @@ getJasmineRequireObj().interface = function(jasmine, env) {
|
|||||||
return env.clock;
|
return env.clock;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a bare {@link Spy} object. This won't be installed anywhere and will not have any implementation behind it.
|
||||||
|
* @name jasmine.createSpy
|
||||||
|
* @function
|
||||||
|
* @param {String} [name] - Name to give the spy. This will be displayed in failure messages.
|
||||||
|
* @param {Function} [originalFn] - Function to act as the real implementation.
|
||||||
|
* @return {Spy}
|
||||||
|
*/
|
||||||
|
jasmine.createSpy = function(name, originalFn) {
|
||||||
|
return env.createSpy(name, originalFn);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an object with multiple {@link Spy}s as its members.
|
* Create an object with multiple {@link Spy}s as its members.
|
||||||
* @name jasmine.createSpyObj
|
* @name jasmine.createSpyObj
|
||||||
|
|||||||
Reference in New Issue
Block a user