Merge branch 'mockMethodsShortcut' of https://github.com/mbildner/jasmine into mbildner-mockMethodsShortcut

- Merges #1101 from @mbildner
This commit is contained in:
Pivotal
2016-10-17 12:26:03 -07:00
committed by Gregg Van Hove
4 changed files with 95 additions and 14 deletions

View File

@@ -79,6 +79,17 @@ describe('Spies', function () {
});
describe("createSpyObj", function() {
it("should create an object with spy methods and corresponding return values when you call jasmine.createSpyObj() with an object", function () {
var spyObj = jasmineUnderTest.createSpyObj('BaseName', {'method1': 42, 'method2': 'special sauce' });
expect(spyObj.method1()).toEqual(42);
expect(spyObj.method1.and.identity()).toEqual('BaseName.method1');
expect(spyObj.method2()).toEqual('special sauce');
expect(spyObj.method2.and.identity()).toEqual('BaseName.method2');
});
it("should create an object with a bunch of spy methods when you call jasmine.createSpyObj()", function() {
var spyObj = jasmineUnderTest.createSpyObj('BaseName', ['method1', 'method2']);
@@ -95,10 +106,22 @@ describe('Spies', function () {
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 or object argument", function() {
expect(function() {
jasmineUnderTest.createSpyObj('BaseName');
}).toThrow("createSpyObj requires a non-empty array of method names to create spies for");
}).toThrow("createSpyObj requires a non-empty array or object of method names to create spies for");
});
it("should throw if you pass an empty array argument", function() {
expect(function() {
jasmineUnderTest.createSpyObj('BaseName', []);
}).toThrow("createSpyObj requires a non-empty array or object of method names to create spies for");
});
it("should throw if you pass an empty object argument", function() {
expect(function() {
jasmineUnderTest.createSpyObj('BaseName', {});
}).toThrow("createSpyObj requires a non-empty array or object of method names to create spies for");
});
});
});

View File

@@ -15,6 +15,22 @@ describe("jasmineUnderTest.util", function() {
});
});
describe("isObject_", function() {
it("should return true if the argument is an object", function() {
expect(jasmineUnderTest.isObject_({})).toBe(true);
expect(jasmineUnderTest.isObject_({an: "object"})).toBe(true);
});
it("should return false if the argument is not an object", function() {
expect(jasmineUnderTest.isObject_(undefined)).toBe(false);
expect(jasmineUnderTest.isObject_([])).toBe(false);
expect(jasmineUnderTest.isObject_(function() {})).toBe(false);
expect(jasmineUnderTest.isObject_('foo')).toBe(false);
expect(jasmineUnderTest.isObject_(5)).toBe(false);
expect(jasmineUnderTest.isObject_(null)).toBe(false);
});
});
describe("isUndefined", function() {
it("reports if a variable is defined", function() {
var a;