jasmine-core 1.3.1 → 2.0.0.rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/jasmine-core.rb +14 -1
- data/lib/jasmine-core/boot.js +131 -0
- data/lib/jasmine-core/boot/boot.js +109 -0
- data/lib/jasmine-core/example/spec/PlayerSpec.js +2 -2
- data/lib/jasmine-core/example/spec/SpecHelper.js +14 -8
- data/lib/jasmine-core/jasmine-html.js +289 -616
- data/lib/jasmine-core/jasmine.css +52 -80
- data/lib/jasmine-core/jasmine.js +1972 -2211
- data/lib/jasmine-core/spec/console/ConsoleReporterSpec.js +161 -386
- data/lib/jasmine-core/spec/core/AnySpec.js +45 -0
- data/lib/jasmine-core/spec/core/CallTrackerSpec.js +105 -0
- data/lib/jasmine-core/spec/core/ClockSpec.js +314 -0
- data/lib/jasmine-core/spec/core/CustomMatchersSpec.js +96 -97
- data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +179 -0
- data/lib/jasmine-core/spec/core/EnvSpec.js +454 -102
- data/lib/jasmine-core/spec/core/ExceptionFormatterSpec.js +56 -0
- data/lib/jasmine-core/spec/core/ExceptionsSpec.js +15 -126
- data/lib/jasmine-core/spec/core/ExpectationResultSpec.js +61 -0
- data/lib/jasmine-core/spec/core/ExpectationSpec.js +320 -0
- data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +150 -38
- data/lib/jasmine-core/spec/core/ObjectContainingSpec.js +64 -0
- data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +43 -42
- data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +147 -0
- data/lib/jasmine-core/spec/core/ReportDispatcherSpec.js +40 -0
- data/lib/jasmine-core/spec/core/SpecRunningSpec.js +92 -1075
- data/lib/jasmine-core/spec/core/SpecSpec.js +215 -95
- data/lib/jasmine-core/spec/core/SpySpec.js +28 -196
- data/lib/jasmine-core/spec/core/SpyStrategySpec.js +101 -0
- data/lib/jasmine-core/spec/core/SuiteSpec.js +216 -106
- data/lib/jasmine-core/spec/core/TimerSpec.js +13 -0
- data/lib/jasmine-core/spec/core/UtilSpec.js +19 -30
- data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +219 -0
- data/lib/jasmine-core/spec/core/matchers/toBeCloseToSpec.js +51 -0
- data/lib/jasmine-core/spec/core/matchers/toBeDefinedSpec.js +18 -0
- data/lib/jasmine-core/spec/core/matchers/toBeFalsySpec.js +38 -0
- data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanSpec.js +19 -0
- data/lib/jasmine-core/spec/core/matchers/toBeLessThanSpec.js +20 -0
- data/lib/jasmine-core/spec/core/matchers/toBeNaNSpec.js +36 -0
- data/lib/jasmine-core/spec/core/matchers/toBeNullSpec.js +17 -0
- data/lib/jasmine-core/spec/core/matchers/toBeSpec.js +17 -0
- data/lib/jasmine-core/spec/core/matchers/toBeTruthySpec.js +38 -0
- data/lib/jasmine-core/spec/core/matchers/toBeUndefinedSpec.js +17 -0
- data/lib/jasmine-core/spec/core/matchers/toContainSpec.js +24 -0
- data/lib/jasmine-core/spec/core/matchers/toEqualSpec.js +28 -0
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledSpec.js +46 -0
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledWithSpec.js +57 -0
- data/lib/jasmine-core/spec/core/matchers/toMatchSpec.js +34 -0
- data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +280 -0
- data/lib/jasmine-core/spec/core/matchers/toThrowSpec.js +98 -0
- data/lib/jasmine-core/spec/helpers/BrowserFlags.js +19 -0
- data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +494 -0
- data/lib/jasmine-core/spec/html/HtmlSpecFilterSpec.js +18 -0
- data/lib/jasmine-core/spec/html/MatchersHtmlSpec.js +8 -8
- data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +3 -3
- data/lib/jasmine-core/spec/html/QueryStringSpec.js +43 -0
- data/lib/jasmine-core/spec/html/ResultsNodeSpec.js +62 -0
- data/lib/jasmine-core/spec/node_suite.js +137 -79
- data/lib/jasmine-core/spec/performance/performance_test.js +10 -0
- data/lib/jasmine-core/spec/support/dev_boot.js +118 -0
- data/lib/jasmine-core/version.rb +5 -2
- metadata +47 -103
- data/lib/jasmine-core/example/SpecRunner.html +0 -54
- data/lib/jasmine-core/spec/core/BaseSpec.js +0 -27
- data/lib/jasmine-core/spec/core/MatchersSpec.js +0 -1157
- data/lib/jasmine-core/spec/core/MockClockSpec.js +0 -38
- data/lib/jasmine-core/spec/core/MultiReporterSpec.js +0 -45
- data/lib/jasmine-core/spec/core/NestedResultsSpec.js +0 -54
- data/lib/jasmine-core/spec/core/QueueSpec.js +0 -23
- data/lib/jasmine-core/spec/core/ReporterSpec.js +0 -56
- data/lib/jasmine-core/spec/core/RunnerSpec.js +0 -280
- data/lib/jasmine-core/spec/core/WaitsForBlockSpec.js +0 -118
- data/lib/jasmine-core/spec/html/HTMLReporterSpec.js +0 -209
- data/lib/jasmine-core/spec/html/TrivialReporterSpec.js +0 -239
@@ -0,0 +1,17 @@
|
|
1
|
+
describe("toBeNull", function() {
|
2
|
+
it("passes for null", function() {
|
3
|
+
var matcher = j$.matchers.toBeNull(),
|
4
|
+
result;
|
5
|
+
|
6
|
+
result = matcher.compare(null);
|
7
|
+
expect(result.pass).toBe(true);
|
8
|
+
});
|
9
|
+
|
10
|
+
it("fails for non-null", function() {
|
11
|
+
var matcher = j$.matchers.toBeNull(),
|
12
|
+
result;
|
13
|
+
|
14
|
+
result = matcher.compare('foo');
|
15
|
+
expect(result.pass).toBe(false);
|
16
|
+
});
|
17
|
+
});
|
@@ -0,0 +1,17 @@
|
|
1
|
+
describe("toBe", function() {
|
2
|
+
it("passes when actual === expected", function() {
|
3
|
+
var matcher = j$.matchers.toBe(),
|
4
|
+
result;
|
5
|
+
|
6
|
+
result = matcher.compare(1, 1);
|
7
|
+
expect(result.pass).toBe(true);
|
8
|
+
});
|
9
|
+
|
10
|
+
it("fails when actual !== expected", function() {
|
11
|
+
var matcher = j$.matchers.toBe(),
|
12
|
+
result;
|
13
|
+
|
14
|
+
result = matcher.compare(1, 2);
|
15
|
+
expect(result.pass).toBe(false);
|
16
|
+
});
|
17
|
+
});
|
@@ -0,0 +1,38 @@
|
|
1
|
+
describe("toBeTruthy", function() {
|
2
|
+
it("passes for 'truthy' values", function() {
|
3
|
+
var matcher = j$.matchers.toBeTruthy(),
|
4
|
+
result;
|
5
|
+
|
6
|
+
result = matcher.compare(true);
|
7
|
+
expect(result.pass).toBe(true);
|
8
|
+
|
9
|
+
result = matcher.compare(1);
|
10
|
+
expect(result.pass).toBe(true);
|
11
|
+
|
12
|
+
result = matcher.compare("foo");
|
13
|
+
expect(result.pass).toBe(true);
|
14
|
+
|
15
|
+
result = matcher.compare({});
|
16
|
+
expect(result.pass).toBe(true);
|
17
|
+
});
|
18
|
+
|
19
|
+
it("fails for 'falsy' values", function() {
|
20
|
+
var matcher = j$.matchers.toBeTruthy(),
|
21
|
+
result;
|
22
|
+
|
23
|
+
result = matcher.compare(false);
|
24
|
+
expect(result.pass).toBe(false);
|
25
|
+
|
26
|
+
result = matcher.compare(0);
|
27
|
+
expect(result.pass).toBe(false);
|
28
|
+
|
29
|
+
result = matcher.compare('');
|
30
|
+
expect(result.pass).toBe(false);
|
31
|
+
|
32
|
+
result = matcher.compare(null);
|
33
|
+
expect(result.pass).toBe(false);
|
34
|
+
|
35
|
+
result = matcher.compare(void 0);
|
36
|
+
expect(result.pass).toBe(false);
|
37
|
+
});
|
38
|
+
});
|
@@ -0,0 +1,17 @@
|
|
1
|
+
describe("toBeUndefined", function() {
|
2
|
+
it("passes for undefined values", function() {
|
3
|
+
var matcher = j$.matchers.toBeUndefined(),
|
4
|
+
result;
|
5
|
+
|
6
|
+
result = matcher.compare(void 0);
|
7
|
+
expect(result.pass).toBe(true);
|
8
|
+
|
9
|
+
});
|
10
|
+
|
11
|
+
it("fails when matching defined values", function() {
|
12
|
+
var matcher = j$.matchers.toBeUndefined();
|
13
|
+
|
14
|
+
result = matcher.compare('foo');
|
15
|
+
expect(result.pass).toBe(false);
|
16
|
+
})
|
17
|
+
});
|
@@ -0,0 +1,24 @@
|
|
1
|
+
describe("toContain", function() {
|
2
|
+
it("delegates to j$.matchersUtil.contains", function() {
|
3
|
+
var util = {
|
4
|
+
contains: jasmine.createSpy('delegated-contains').and.callReturn(true)
|
5
|
+
},
|
6
|
+
matcher = j$.matchers.toContain(util);
|
7
|
+
|
8
|
+
result = matcher.compare("ABC", "B");
|
9
|
+
expect(util.contains).toHaveBeenCalledWith("ABC", "B", []);
|
10
|
+
expect(result.pass).toBe(true);
|
11
|
+
});
|
12
|
+
|
13
|
+
it("delegates to j$.matchersUtil.contains, passing in equality testers if present", function() {
|
14
|
+
var util = {
|
15
|
+
contains: jasmine.createSpy('delegated-contains').and.callReturn(true)
|
16
|
+
},
|
17
|
+
customEqualityTesters = ['a', 'b'],
|
18
|
+
matcher = j$.matchers.toContain(util, customEqualityTesters);
|
19
|
+
|
20
|
+
result = matcher.compare("ABC", "B");
|
21
|
+
expect(util.contains).toHaveBeenCalledWith("ABC", "B", ['a', 'b']);
|
22
|
+
expect(result.pass).toBe(true);
|
23
|
+
});
|
24
|
+
});
|
@@ -0,0 +1,28 @@
|
|
1
|
+
describe("toEqual", function() {
|
2
|
+
it("delegates to equals function", function() {
|
3
|
+
var util = {
|
4
|
+
equals: jasmine.createSpy('delegated-equals').and.callReturn(true)
|
5
|
+
},
|
6
|
+
matcher = j$.matchers.toEqual(util),
|
7
|
+
result;
|
8
|
+
|
9
|
+
result = matcher.compare(1, 1);
|
10
|
+
|
11
|
+
expect(util.equals).toHaveBeenCalledWith(1, 1, []);
|
12
|
+
expect(result.pass).toBe(true);
|
13
|
+
});
|
14
|
+
|
15
|
+
it("delegates custom equality testers, if present", function() {
|
16
|
+
var util = {
|
17
|
+
equals: jasmine.createSpy('delegated-equals').and.callReturn(true)
|
18
|
+
},
|
19
|
+
customEqualityTesters = ['a', 'b'],
|
20
|
+
matcher = j$.matchers.toEqual(util, customEqualityTesters),
|
21
|
+
result;
|
22
|
+
|
23
|
+
result = matcher.compare(1, 1);
|
24
|
+
|
25
|
+
expect(util.equals).toHaveBeenCalledWith(1, 1, ['a', 'b']);
|
26
|
+
expect(result.pass).toBe(true);
|
27
|
+
});
|
28
|
+
});
|
@@ -0,0 +1,46 @@
|
|
1
|
+
describe("toHaveBeenCalled", function() {
|
2
|
+
it("passes when the actual was called, with a custom .not fail message", function() {
|
3
|
+
var matcher = j$.matchers.toHaveBeenCalled(),
|
4
|
+
calledSpy = j$.createSpy('called-spy'),
|
5
|
+
result;
|
6
|
+
|
7
|
+
calledSpy();
|
8
|
+
|
9
|
+
result = matcher.compare(calledSpy);
|
10
|
+
expect(result.pass).toBe(true);
|
11
|
+
expect(result.message).toEqual("Expected spy called-spy not to have been called.");
|
12
|
+
});
|
13
|
+
|
14
|
+
it("fails when the actual was not called", function() {
|
15
|
+
var matcher = j$.matchers.toHaveBeenCalled(),
|
16
|
+
uncalledSpy = j$.createSpy('uncalled spy');
|
17
|
+
|
18
|
+
result = matcher.compare(uncalledSpy);
|
19
|
+
expect(result.pass).toBe(false);
|
20
|
+
});
|
21
|
+
|
22
|
+
it("throws an exception when the actual is not a spy", function() {
|
23
|
+
var matcher = j$.matchers.toHaveBeenCalled(),
|
24
|
+
fn = function() {};
|
25
|
+
|
26
|
+
expect(function() { matcher.compare(fn) }).toThrow(new Error("Expected a spy, but got Function."));
|
27
|
+
});
|
28
|
+
|
29
|
+
it("throws an exception when invoked with any arguments", function() {
|
30
|
+
var matcher = j$.matchers.toHaveBeenCalled(),
|
31
|
+
spy = j$.createSpy('sample spy');
|
32
|
+
|
33
|
+
expect(function() { matcher.compare(spy, 'foo') }).toThrow(new Error("toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith"));
|
34
|
+
});
|
35
|
+
|
36
|
+
it("has a custom message on failure", function() {
|
37
|
+
var matcher = j$.matchers.toHaveBeenCalled(),
|
38
|
+
spy = j$.createSpy('sample-spy'),
|
39
|
+
result;
|
40
|
+
|
41
|
+
result = matcher.compare(spy);
|
42
|
+
|
43
|
+
expect(result.message).toEqual("Expected spy sample-spy to have been called.");
|
44
|
+
});
|
45
|
+
});
|
46
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
describe("toHaveBeenCalledWith", function() {
|
2
|
+
it("passes when the actual was called with matching parameters", function() {
|
3
|
+
var util = {
|
4
|
+
contains: jasmine.createSpy('delegated-contains').and.callReturn(true)
|
5
|
+
},
|
6
|
+
matcher = j$.matchers.toHaveBeenCalledWith(util),
|
7
|
+
calledSpy = j$.createSpy('called-spy'),
|
8
|
+
result;
|
9
|
+
|
10
|
+
calledSpy('a', 'b');
|
11
|
+
result = matcher.compare(calledSpy, 'a', 'b');
|
12
|
+
|
13
|
+
expect(result.pass).toBe(true);
|
14
|
+
});
|
15
|
+
|
16
|
+
it("fails when the actual was not called", function() {
|
17
|
+
var util = {
|
18
|
+
contains: jasmine.createSpy('delegated-contains').and.callReturn(false)
|
19
|
+
},
|
20
|
+
matcher = j$.matchers.toHaveBeenCalledWith(util),
|
21
|
+
uncalledSpy = j$.createSpy('uncalled spy'),
|
22
|
+
result;
|
23
|
+
|
24
|
+
result = matcher.compare(uncalledSpy);
|
25
|
+
expect(result.pass).toBe(false);
|
26
|
+
});
|
27
|
+
|
28
|
+
it("fails when the actual was called with different parameters", function() {
|
29
|
+
var util = {
|
30
|
+
contains: jasmine.createSpy('delegated-contains').and.callReturn(false)
|
31
|
+
},
|
32
|
+
matcher = j$.matchers.toHaveBeenCalledWith(util),
|
33
|
+
calledSpy = j$.createSpy('called spy'),
|
34
|
+
result;
|
35
|
+
|
36
|
+
calledSpy('a');
|
37
|
+
result = matcher.compare(calledSpy, 'a', 'b');
|
38
|
+
|
39
|
+
expect(result.pass).toBe(false);
|
40
|
+
});
|
41
|
+
|
42
|
+
it("throws an exception when the actual is not a spy", function() {
|
43
|
+
var matcher = j$.matchers.toHaveBeenCalledWith(),
|
44
|
+
fn = function() {};
|
45
|
+
|
46
|
+
expect(function() { matcher.compare(fn) }).toThrow(new Error("Expected a spy, but got Function."));
|
47
|
+
});
|
48
|
+
|
49
|
+
it("has a custom message on failure", function() {
|
50
|
+
var matcher = j$.matchers.toHaveBeenCalledWith(),
|
51
|
+
spy = j$.createSpy('sample-spy'),
|
52
|
+
messages = matcher.message(spy);
|
53
|
+
|
54
|
+
expect(messages.affirmative).toEqual("Expected spy sample-spy to have been called.")
|
55
|
+
expect(messages.negative).toEqual("Expected spy sample-spy not to have been called.")
|
56
|
+
});
|
57
|
+
});
|
@@ -0,0 +1,34 @@
|
|
1
|
+
describe("toMatch", function() {
|
2
|
+
it("passes when RegExps are equivalent", function() {
|
3
|
+
var matcher = j$.matchers.toMatch(),
|
4
|
+
result;
|
5
|
+
|
6
|
+
result = matcher.compare(/foo/, /foo/);
|
7
|
+
expect(result.pass).toBe(true);
|
8
|
+
});
|
9
|
+
|
10
|
+
it("fails when RegExps are not equivalent", function() {
|
11
|
+
var matcher = j$.matchers.toMatch(),
|
12
|
+
result;
|
13
|
+
|
14
|
+
result = matcher.compare(/bar/, /foo/);
|
15
|
+
expect(result.pass).toBe(false);
|
16
|
+
});
|
17
|
+
|
18
|
+
it("passes when the actual matches the expected string as a pattern", function() {
|
19
|
+
var matcher = j$.matchers.toMatch(),
|
20
|
+
result;
|
21
|
+
|
22
|
+
result = matcher.compare('foosball', 'foo');
|
23
|
+
expect(result.pass).toBe(true);
|
24
|
+
});
|
25
|
+
|
26
|
+
it("fails when the actual matches the expected string as a pattern", function() {
|
27
|
+
var matcher = j$.matchers.toMatch(),
|
28
|
+
result;
|
29
|
+
|
30
|
+
result = matcher.compare('bar', 'foo');
|
31
|
+
expect(result.pass).toBe(false);
|
32
|
+
});
|
33
|
+
});
|
34
|
+
|
@@ -0,0 +1,280 @@
|
|
1
|
+
describe("toThrowError", function() {
|
2
|
+
it("throws an error when the actual is not a function", function() {
|
3
|
+
var matcher = j$.matchers.toThrowError();
|
4
|
+
|
5
|
+
expect(function() {
|
6
|
+
matcher.compare({});
|
7
|
+
}).toThrow(new Error("Actual is not a Function")); // TODO: this needs to change for self-test
|
8
|
+
});
|
9
|
+
|
10
|
+
it("throws an error when the expected is not an Error, string, or RegExp", function() {
|
11
|
+
var matcher = j$.matchers.toThrowError(),
|
12
|
+
fn = function() {
|
13
|
+
throw new Error("foo");
|
14
|
+
};
|
15
|
+
|
16
|
+
expect(function() {
|
17
|
+
matcher.compare(fn, 1);
|
18
|
+
}).toThrow(new Error("Expected is not an Error, string, or RegExp.")); // TODO: this needs to change for self-test
|
19
|
+
});
|
20
|
+
|
21
|
+
it("throws an error when the expected error type is not an Error", function() {
|
22
|
+
var matcher = j$.matchers.toThrowError(),
|
23
|
+
fn = function() {
|
24
|
+
throw new Error("foo");
|
25
|
+
};
|
26
|
+
|
27
|
+
expect(function() {
|
28
|
+
matcher.compare(fn, void 0, "foo");
|
29
|
+
}).toThrow(new Error("Expected error type is not an Error.")); // TODO: this needs to change for self-test
|
30
|
+
});
|
31
|
+
|
32
|
+
it("throws an error when the expected error message is not a string or RegExp", function() {
|
33
|
+
var matcher = j$.matchers.toThrowError(),
|
34
|
+
fn = function() {
|
35
|
+
throw new Error("foo");
|
36
|
+
};
|
37
|
+
|
38
|
+
expect(function() {
|
39
|
+
matcher.compare(fn, Error, 1);
|
40
|
+
}).toThrow(new Error("Expected error message is not a string or RegExp.")); // TODO: this needs to change for self-test
|
41
|
+
});
|
42
|
+
|
43
|
+
it("fails if actual does not throw at all", function() {
|
44
|
+
var matcher = j$.matchers.toThrowError(),
|
45
|
+
fn = function() {
|
46
|
+
return true;
|
47
|
+
},
|
48
|
+
result;
|
49
|
+
|
50
|
+
result = matcher.compare(fn);
|
51
|
+
|
52
|
+
expect(result.pass).toBe(false);
|
53
|
+
expect(result.message).toEqual("Expected function to throw an Error.");
|
54
|
+
});
|
55
|
+
|
56
|
+
it("fails if thrown is not an instanceof Error", function() {
|
57
|
+
var matcher = j$.matchers.toThrowError(),
|
58
|
+
fn = function() {
|
59
|
+
throw 4;
|
60
|
+
},
|
61
|
+
result;
|
62
|
+
|
63
|
+
result = matcher.compare(fn);
|
64
|
+
expect(result.pass).toBe(false);
|
65
|
+
expect(result.message).toEqual("Expected function to throw an Error, but it threw 4.");
|
66
|
+
});
|
67
|
+
|
68
|
+
it("fails with the correct message if thrown is a falsy value", function() {
|
69
|
+
var matcher = j$.matchers.toThrowError(),
|
70
|
+
fn = function() {
|
71
|
+
throw undefined;
|
72
|
+
},
|
73
|
+
result;
|
74
|
+
|
75
|
+
result = matcher.compare(fn);
|
76
|
+
expect(result.pass).toBe(false);
|
77
|
+
expect(result.message).toEqual("Expected function to throw an Error, but it threw undefined.");
|
78
|
+
});
|
79
|
+
|
80
|
+
it("passes if thrown is a type of Error, but there is no expected error", function() {
|
81
|
+
var matcher = j$.matchers.toThrowError(),
|
82
|
+
fn = function() {
|
83
|
+
throw new TypeError();
|
84
|
+
},
|
85
|
+
result;
|
86
|
+
|
87
|
+
result = matcher.compare(fn);
|
88
|
+
|
89
|
+
expect(result.pass).toBe(true);
|
90
|
+
expect(result.message).toEqual("Expected function not to throw an Error, but it threw TypeError.");
|
91
|
+
});
|
92
|
+
|
93
|
+
it("passes if thrown is an Error and the expected is the same message", function() {
|
94
|
+
var matcher = j$.matchers.toThrowError(),
|
95
|
+
fn = function() {
|
96
|
+
throw new Error("foo");
|
97
|
+
},
|
98
|
+
result;
|
99
|
+
|
100
|
+
result = matcher.compare(fn, "foo");
|
101
|
+
|
102
|
+
expect(result.pass).toBe(true);
|
103
|
+
expect(result.message).toEqual("Expected function not to throw an exception with message 'foo'.");
|
104
|
+
});
|
105
|
+
|
106
|
+
it("fails if thrown is an Error and the expected is not the same message", function() {
|
107
|
+
var matcher = j$.matchers.toThrowError(),
|
108
|
+
fn = function() {
|
109
|
+
throw new Error("foo");
|
110
|
+
},
|
111
|
+
result;
|
112
|
+
|
113
|
+
result = matcher.compare(fn, "bar");
|
114
|
+
|
115
|
+
expect(result.pass).toBe(false);
|
116
|
+
expect(result.message).toEqual("Expected function to throw an exception with message 'bar', but it threw an exception with message 'foo'.");
|
117
|
+
});
|
118
|
+
|
119
|
+
it("passes if thrown is an Error and the expected is a RegExp that matches the message", function() {
|
120
|
+
var matcher = j$.matchers.toThrowError(),
|
121
|
+
fn = function() {
|
122
|
+
throw new Error("a long message");
|
123
|
+
},
|
124
|
+
result;
|
125
|
+
|
126
|
+
result = matcher.compare(fn, /long/);
|
127
|
+
|
128
|
+
expect(result.pass).toBe(true);
|
129
|
+
expect(result.message).toEqual("Expected function not to throw an exception with a message matching /long/.");
|
130
|
+
});
|
131
|
+
|
132
|
+
it("fails if thrown is an Error and the expected is a RegExp that does not match the message", function() {
|
133
|
+
var matcher = j$.matchers.toThrowError(),
|
134
|
+
fn = function() {
|
135
|
+
throw new Error("a long message");
|
136
|
+
},
|
137
|
+
result;
|
138
|
+
|
139
|
+
result = matcher.compare(fn, /foo/);
|
140
|
+
|
141
|
+
expect(result.pass).toBe(false);
|
142
|
+
expect(result.message).toEqual("Expected function to throw an exception with a message matching /foo/, but it threw an exception with message 'a long message'.");
|
143
|
+
});
|
144
|
+
|
145
|
+
it("passes if thrown is an Error and the expected the same Error", function() {
|
146
|
+
var util = {
|
147
|
+
equals: jasmine.createSpy('delegated-equal').and.callReturn(true)
|
148
|
+
},
|
149
|
+
matcher = j$.matchers.toThrowError(util),
|
150
|
+
fn = function() {
|
151
|
+
throw new Error();
|
152
|
+
},
|
153
|
+
result;
|
154
|
+
|
155
|
+
result = matcher.compare(fn, Error);
|
156
|
+
|
157
|
+
expect(result.pass).toBe(true);
|
158
|
+
expect(result.message).toEqual("Expected function not to throw Error.");
|
159
|
+
});
|
160
|
+
|
161
|
+
it("passes if thrown is a custom error that takes arguments and the expected is the same error", function() {
|
162
|
+
var util = {
|
163
|
+
equals: jasmine.createSpy('delegated-equal').and.callReturn(true)
|
164
|
+
},
|
165
|
+
matcher = j$.matchers.toThrowError(util),
|
166
|
+
CustomError = function CustomError(arg) { arg.x },
|
167
|
+
fn = function() {
|
168
|
+
throw new CustomError({ x: 1 });
|
169
|
+
},
|
170
|
+
result;
|
171
|
+
|
172
|
+
CustomError.prototype = new Error();
|
173
|
+
CustomError.prototype.constructor = CustomError;
|
174
|
+
|
175
|
+
result = matcher.compare(fn, CustomError);
|
176
|
+
|
177
|
+
expect(result.pass).toBe(true);
|
178
|
+
expect(result.message).toEqual("Expected function not to throw CustomError.");
|
179
|
+
});
|
180
|
+
|
181
|
+
it("fails if thrown is an Error and the expected is a different Error", function() {
|
182
|
+
var util = {
|
183
|
+
equals: jasmine.createSpy('delegated-equal').and.callReturn(false)
|
184
|
+
},
|
185
|
+
matcher = j$.matchers.toThrowError(util),
|
186
|
+
fn = function() {
|
187
|
+
throw new Error();
|
188
|
+
},
|
189
|
+
result;
|
190
|
+
|
191
|
+
result = matcher.compare(fn, TypeError);
|
192
|
+
|
193
|
+
expect(result.pass).toBe(false);
|
194
|
+
expect(result.message).toEqual("Expected function to throw TypeError, but it threw Error.");
|
195
|
+
});
|
196
|
+
|
197
|
+
it("passes if thrown is a type of Error and it is equal to the expected Error and message", function() {
|
198
|
+
var util = {
|
199
|
+
equals: jasmine.createSpy('delegated-equal').and.callReturn(true)
|
200
|
+
},
|
201
|
+
matcher = j$.matchers.toThrowError(util),
|
202
|
+
fn = function() {
|
203
|
+
throw new TypeError("foo");
|
204
|
+
},
|
205
|
+
result;
|
206
|
+
|
207
|
+
result = matcher.compare(fn, TypeError, "foo");
|
208
|
+
|
209
|
+
expect(result.pass).toBe(true);
|
210
|
+
expect(result.message).toEqual("Expected function not to throw TypeError with message \"foo\".");
|
211
|
+
});
|
212
|
+
|
213
|
+
it("passes if thrown is a custom error that takes arguments and it is equal to the expected custom error and message", function() {
|
214
|
+
var util = {
|
215
|
+
equals: jasmine.createSpy('delegated-equal').and.callReturn(true)
|
216
|
+
},
|
217
|
+
matcher = j$.matchers.toThrowError(util),
|
218
|
+
CustomError = function CustomError(arg) { this.message = arg.message },
|
219
|
+
fn = function() {
|
220
|
+
throw new CustomError({message: "foo"});
|
221
|
+
},
|
222
|
+
result;
|
223
|
+
|
224
|
+
CustomError.prototype = new Error();
|
225
|
+
CustomError.prototype.constructor = CustomError;
|
226
|
+
|
227
|
+
result = matcher.compare(fn, CustomError, "foo");
|
228
|
+
|
229
|
+
expect(result.pass).toBe(true);
|
230
|
+
expect(result.message).toEqual("Expected function not to throw CustomError with message \"foo\".");
|
231
|
+
});
|
232
|
+
|
233
|
+
it("fails if thrown is a type of Error and the expected is a different Error", function() {
|
234
|
+
var util = {
|
235
|
+
equals: jasmine.createSpy('delegated-equal').and.callReturn(false)
|
236
|
+
},
|
237
|
+
matcher = j$.matchers.toThrowError(util),
|
238
|
+
fn = function() {
|
239
|
+
throw new TypeError("foo");
|
240
|
+
},
|
241
|
+
result;
|
242
|
+
|
243
|
+
result = matcher.compare(fn, TypeError, "bar");
|
244
|
+
|
245
|
+
expect(result.pass).toBe(false);
|
246
|
+
expect(result.message).toEqual("Expected function to throw TypeError with message \"bar\", but it threw TypeError with message \"foo\".");
|
247
|
+
});
|
248
|
+
|
249
|
+
it("passes if thrown is a type of Error and has the same type as the expected Error and the message matches the exepcted message", function() {
|
250
|
+
var util = {
|
251
|
+
equals: jasmine.createSpy('delegated-equal').and.callReturn(true)
|
252
|
+
},
|
253
|
+
matcher = j$.matchers.toThrowError(util),
|
254
|
+
fn = function() {
|
255
|
+
throw new TypeError("foo");
|
256
|
+
},
|
257
|
+
result;
|
258
|
+
|
259
|
+
result = matcher.compare(fn, TypeError, /foo/);
|
260
|
+
|
261
|
+
expect(result.pass).toBe(true);
|
262
|
+
expect(result.message).toEqual("Expected function not to throw TypeError with message matching /foo/.");
|
263
|
+
});
|
264
|
+
|
265
|
+
it("fails if thrown is a type of Error and the expected is a different Error", function() {
|
266
|
+
var util = {
|
267
|
+
equals: jasmine.createSpy('delegated-equal').and.callReturn(false)
|
268
|
+
},
|
269
|
+
matcher = j$.matchers.toThrowError(util),
|
270
|
+
fn = function() {
|
271
|
+
throw new TypeError("foo");
|
272
|
+
},
|
273
|
+
result;
|
274
|
+
|
275
|
+
result = matcher.compare(fn, TypeError, /bar/);
|
276
|
+
|
277
|
+
expect(result.pass).toBe(false);
|
278
|
+
expect(result.message).toEqual("Expected function to throw TypeError with message matching /bar/, but it threw TypeError with message \"foo\".");
|
279
|
+
});
|
280
|
+
});
|