Improve errors with the domaine and how to use the API
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
describe('formatErrorMsg', function () {
|
||||
|
||||
it('should return a factory', function() {
|
||||
expect(typeof jasmineUnderTest.formatErrorMsg).toBe('function');
|
||||
});
|
||||
|
||||
|
||||
describe('Format an error with a domain', function() {
|
||||
|
||||
var formator;
|
||||
|
||||
beforeEach(function() {
|
||||
formator = jasmineUnderTest.formatErrorMsg('api');
|
||||
});
|
||||
|
||||
it('should format the output', function() {
|
||||
expect(formator('message').trim()).toBe('api : message');
|
||||
expect(formator('message2').trim()).toBe('api : message2');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('Format an error with a domain and usage', function() {
|
||||
|
||||
var formator;
|
||||
|
||||
beforeEach(function() {
|
||||
formator = jasmineUnderTest.formatErrorMsg('api', 'with a param');
|
||||
});
|
||||
|
||||
it('should format the output', function() {
|
||||
expect(formator('message').trim()).toBe('api : message\nUsage: with a param');
|
||||
expect(formator('message2').trim()).toBe('api : message2\nUsage: with a param');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Format an error with a domain, usage, Tips', function() {
|
||||
|
||||
var formator;
|
||||
|
||||
beforeEach(function() {
|
||||
formator = jasmineUnderTest.formatErrorMsg('api', 'with a param', 'you can do it');
|
||||
});
|
||||
|
||||
it('should format the output', function() {
|
||||
expect(formator('message').trim()).toBe('api : message\nUsage: with a param\nTips: you can do it');
|
||||
expect(formator('message2').trim()).toBe('api : message2\nUsage: with a param\nTips: you can do it');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Format an error with a domain no usage and Tips', function() {
|
||||
|
||||
var formator;
|
||||
|
||||
beforeEach(function() {
|
||||
formator = jasmineUnderTest.formatErrorMsg('api', null, 'you can do it');
|
||||
});
|
||||
|
||||
it('should format the output', function() {
|
||||
expect(formator('message').trim()).toBe('api : message\nTips: you can do it');
|
||||
expect(formator('message2').trim()).toBe('api : message2\nTips: you can do it');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
@@ -24,14 +24,14 @@ describe("toHaveBeenCalled", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
||||
fn = function() {};
|
||||
|
||||
expect(function() { matcher.compare(fn) }).toThrow(new Error("Expected a spy, but got Function."));
|
||||
expect(function() { matcher.compare(fn) }).toThrowError(Error, /Expected a spy, but got Function./);
|
||||
});
|
||||
|
||||
it("throws an exception when invoked with any arguments", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
||||
spy = jasmineUnderTest.createSpy('sample spy');
|
||||
|
||||
expect(function() { matcher.compare(spy, 'foo') }).toThrow(new Error("toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith"));
|
||||
expect(function() { matcher.compare(spy, 'foo') }).toThrowError(Error, /It does not take arguments, use toHaveBeenCalledWith/);
|
||||
});
|
||||
|
||||
it("has a custom message on failure", function() {
|
||||
|
||||
@@ -24,7 +24,7 @@ describe("toHaveBeenCalledTimes", function() {
|
||||
spy();
|
||||
expect(function() {
|
||||
matcher.compare(spy);
|
||||
}).toThrowError('The expected times failed is a required argument and must be a number.');
|
||||
}).toThrowError(/The expected times failed is a required argument and must be a number./);
|
||||
});
|
||||
|
||||
it("fails when the actual was called less than the expected", function() {
|
||||
@@ -54,7 +54,7 @@ describe("toHaveBeenCalledTimes", function() {
|
||||
|
||||
expect(function() {
|
||||
matcher.compare(fn);
|
||||
}).toThrowError("Expected a spy, but got Function.");
|
||||
}).toThrowError(/Expected a spy, but got Function./);
|
||||
});
|
||||
|
||||
it("has a custom message on failure that tells it was called only once", function() {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
describe("toHaveBeenCalledWith", function() {
|
||||
|
||||
it("passes when the actual was called with matching parameters", function() {
|
||||
var util = {
|
||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
|
||||
@@ -61,6 +62,6 @@ describe("toHaveBeenCalledWith", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(),
|
||||
fn = function() {};
|
||||
|
||||
expect(function() { matcher.compare(fn) }).toThrow(new Error("Expected a spy, but got Function."));
|
||||
expect(function() { matcher.compare(fn) }).toThrowError(/Expected a spy, but got Function./);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
describe("toMatch", function() {
|
||||
|
||||
it("passes when RegExps are equivalent", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toMatch(),
|
||||
result;
|
||||
@@ -36,7 +37,7 @@ describe("toMatch", function() {
|
||||
|
||||
expect(function() {
|
||||
matcher.compare('foo', { bar: 'baz' });
|
||||
}).toThrowError('Expected is not a String or a RegExp');
|
||||
}).toThrowError(/Expected is not a String or a RegExp/);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ describe("toThrowError", function() {
|
||||
|
||||
expect(function() {
|
||||
matcher.compare({});
|
||||
}).toThrowError("Actual is not a Function");
|
||||
}).toThrowError(/Actual is not a Function/);
|
||||
});
|
||||
|
||||
it("throws an error when the expected is not an Error, string, or RegExp", function() {
|
||||
@@ -15,7 +15,7 @@ describe("toThrowError", function() {
|
||||
|
||||
expect(function() {
|
||||
matcher.compare(fn, 1);
|
||||
}).toThrowError("Expected is not an Error, string, or RegExp.");
|
||||
}).toThrowError(/Expected is not an Error, string, or RegExp./);
|
||||
});
|
||||
|
||||
it("throws an error when the expected error type is not an Error", function() {
|
||||
@@ -26,7 +26,7 @@ describe("toThrowError", function() {
|
||||
|
||||
expect(function() {
|
||||
matcher.compare(fn, void 0, "foo");
|
||||
}).toThrowError("Expected error type is not an Error.");
|
||||
}).toThrowError(/Expected error type is not an Error./);
|
||||
});
|
||||
|
||||
it("throws an error when the expected error message is not a string or RegExp", function() {
|
||||
@@ -37,7 +37,7 @@ describe("toThrowError", function() {
|
||||
|
||||
expect(function() {
|
||||
matcher.compare(fn, Error, 1);
|
||||
}).toThrowError("Expected error message is not a string or RegExp.");
|
||||
}).toThrowError(/Expected error message is not a string or RegExp./);
|
||||
});
|
||||
|
||||
it("fails if actual does not throw at all", function() {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
describe("toThrow", function() {
|
||||
|
||||
it("throws an error when the actual is not a function", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrow();
|
||||
|
||||
expect(function() {
|
||||
matcher.compare({});
|
||||
matcherComparator({});
|
||||
}).toThrowError("Actual is not a Function");
|
||||
}).toThrowError(/Actual is not a Function/);
|
||||
});
|
||||
|
||||
it("fails if actual does not throw", function() {
|
||||
|
||||
Reference in New Issue
Block a user