Allow createSpyObj to be called with just an array of method names
[Finish #50757607] #321
This commit is contained in:
@@ -209,6 +209,11 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
j$.createSpyObj = function(baseName, methodNames) {
|
j$.createSpyObj = function(baseName, methodNames) {
|
||||||
|
if (j$.isArray_(baseName) && j$.util.isUndefined(methodNames)) {
|
||||||
|
methodNames = baseName;
|
||||||
|
baseName = 'unknown';
|
||||||
|
}
|
||||||
|
|
||||||
if (!j$.isArray_(methodNames) || methodNames.length === 0) {
|
if (!j$.isArray_(methodNames) || methodNames.length === 0) {
|
||||||
throw 'createSpyObj requires a non-empty array of method names to create spies for';
|
throw 'createSpyObj requires a non-empty array of method names to create spies for';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,14 @@ describe('Spies', function () {
|
|||||||
expect(spyObj.method2.and.identity()).toEqual('BaseName.method2');
|
expect(spyObj.method2.and.identity()).toEqual('BaseName.method2');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should allow you to omit the baseName", function() {
|
||||||
|
var spyObj = j$.createSpyObj(['method1', 'method2']);
|
||||||
|
|
||||||
|
expect(spyObj).toEqual({ method1: jasmine.any(Function), method2: jasmine.any(Function)});
|
||||||
|
expect(spyObj.method1.and.identity()).toEqual('unknown.method1');
|
||||||
|
expect(spyObj.method2.and.identity()).toEqual('unknown.method2');
|
||||||
|
});
|
||||||
|
|
||||||
it("should throw if you do not pass an array argument", function() {
|
it("should throw if you do not pass an array argument", function() {
|
||||||
expect(function() {
|
expect(function() {
|
||||||
j$.createSpyObj('BaseName');
|
j$.createSpyObj('BaseName');
|
||||||
|
|||||||
@@ -105,6 +105,11 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
j$.createSpyObj = function(baseName, methodNames) {
|
j$.createSpyObj = function(baseName, methodNames) {
|
||||||
|
if (j$.isArray_(baseName) && j$.util.isUndefined(methodNames)) {
|
||||||
|
methodNames = baseName;
|
||||||
|
baseName = 'unknown';
|
||||||
|
}
|
||||||
|
|
||||||
if (!j$.isArray_(methodNames) || methodNames.length === 0) {
|
if (!j$.isArray_(methodNames) || methodNames.length === 0) {
|
||||||
throw 'createSpyObj requires a non-empty array of method names to create spies for';
|
throw 'createSpyObj requires a non-empty array of method names to create spies for';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user