jasmine-core 2.99.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jasmine-core/boot.js +7 -6
- data/lib/jasmine-core/boot/boot.js +7 -6
- data/lib/jasmine-core/boot/node_boot.js +0 -3
- data/lib/jasmine-core/jasmine-html.js +228 -137
- data/lib/jasmine-core/jasmine.css +11 -5
- data/lib/jasmine-core/jasmine.js +1046 -608
- data/lib/jasmine-core/node_boot.js +0 -3
- data/lib/jasmine-core/spec/core/CallTrackerSpec.js +130 -0
- data/lib/jasmine-core/spec/core/ClearStackSpec.js +137 -0
- data/lib/jasmine-core/spec/core/ClockSpec.js +710 -0
- data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +286 -0
- data/lib/jasmine-core/spec/core/EnvSpec.js +200 -0
- data/lib/jasmine-core/spec/core/ExceptionFormatterSpec.js +120 -0
- data/lib/jasmine-core/spec/core/ExceptionsSpec.js +46 -0
- data/lib/jasmine-core/spec/core/ExpectationResultSpec.js +61 -0
- data/lib/jasmine-core/spec/core/ExpectationSpec.js +434 -0
- data/lib/jasmine-core/spec/core/GlobalErrorsSpec.js +110 -0
- data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +259 -0
- data/lib/jasmine-core/spec/core/MockDateSpec.js +200 -0
- data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +332 -0
- data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +670 -0
- data/lib/jasmine-core/spec/core/ReportDispatcherSpec.js +140 -0
- data/lib/jasmine-core/spec/core/SpecSpec.js +407 -0
- data/lib/jasmine-core/spec/core/SpyRegistrySpec.js +364 -0
- data/lib/jasmine-core/spec/core/SpySpec.js +177 -0
- data/lib/jasmine-core/spec/core/SpyStrategySpec.js +202 -0
- data/lib/jasmine-core/spec/core/StackTraceSpec.js +166 -0
- data/lib/jasmine-core/spec/core/SuiteSpec.js +123 -0
- data/lib/jasmine-core/spec/core/TimerSpec.js +31 -0
- data/lib/jasmine-core/spec/core/TreeProcessorSpec.js +794 -0
- data/lib/jasmine-core/spec/core/UserContextSpec.js +54 -0
- data/lib/jasmine-core/spec/core/UtilSpec.js +105 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/AnySpec.js +91 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/AnythingSpec.js +76 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayContainingSpec.js +52 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayWithExactContentsSpec.js +47 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/ObjectContainingSpec.js +99 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/StringMatchingSpec.js +27 -0
- data/lib/jasmine-core/spec/core/formatErrorMsgSpec.js +13 -0
- data/lib/jasmine-core/spec/core/integration/CustomMatchersSpec.js +200 -0
- data/lib/jasmine-core/spec/core/integration/CustomSpyStrategiesSpec.js +138 -0
- data/lib/jasmine-core/spec/core/integration/EnvSpec.js +2344 -0
- data/lib/jasmine-core/spec/core/integration/SpecRunningSpec.js +976 -0
- data/lib/jasmine-core/spec/core/matchers/DiffBuilderSpec.js +47 -0
- data/lib/jasmine-core/spec/core/matchers/NullDiffBuilderSpec.js +13 -0
- data/lib/jasmine-core/spec/core/matchers/ObjectPathSpec.js +43 -0
- data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +645 -0
- data/lib/jasmine-core/spec/core/matchers/nothingSpec.js +8 -0
- data/lib/jasmine-core/spec/core/matchers/toBeCloseToSpec.js +93 -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/toBeGreaterThanOrEqualSpec.js +29 -0
- data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanSpec.js +20 -0
- data/lib/jasmine-core/spec/core/matchers/toBeLessThanOrEqualSpec.js +29 -0
- data/lib/jasmine-core/spec/core/matchers/toBeLessThanSpec.js +20 -0
- data/lib/jasmine-core/spec/core/matchers/toBeNaNSpec.js +37 -0
- data/lib/jasmine-core/spec/core/matchers/toBeNegativeInfinitySpec.js +31 -0
- data/lib/jasmine-core/spec/core/matchers/toBeNullSpec.js +17 -0
- data/lib/jasmine-core/spec/core/matchers/toBePositiveInfinitySpec.js +31 -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 +18 -0
- data/lib/jasmine-core/spec/core/matchers/toContainSpec.js +26 -0
- data/lib/jasmine-core/spec/core/matchers/toEqualSpec.js +785 -0
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledBeforeSpec.js +99 -0
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledSpec.js +47 -0
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledTimesSpec.js +86 -0
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledWithSpec.js +67 -0
- data/lib/jasmine-core/spec/core/matchers/toMatchSpec.js +43 -0
- data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +315 -0
- data/lib/jasmine-core/spec/core/matchers/toThrowMatchingSpec.js +73 -0
- data/lib/jasmine-core/spec/core/matchers/toThrowSpec.js +100 -0
- data/lib/jasmine-core/spec/helpers/BrowserFlags.js +15 -0
- data/lib/jasmine-core/spec/helpers/asyncAwait.js +27 -0
- data/lib/jasmine-core/spec/helpers/checkForMap.js +37 -0
- data/lib/jasmine-core/spec/helpers/checkForSet.js +41 -0
- data/lib/jasmine-core/spec/helpers/checkForSymbol.js +28 -0
- data/lib/jasmine-core/spec/helpers/checkForTypedArrays.js +20 -0
- data/lib/jasmine-core/spec/helpers/defineJasmineUnderTest.js +6 -0
- data/lib/jasmine-core/spec/helpers/integrationMatchers.js +43 -0
- data/lib/jasmine-core/spec/helpers/nodeDefineJasmineUnderTest.js +30 -0
- data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +1261 -0
- data/lib/jasmine-core/spec/html/HtmlSpecFilterSpec.js +18 -0
- data/lib/jasmine-core/spec/html/MatchersHtmlSpec.js +37 -0
- data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +27 -0
- data/lib/jasmine-core/spec/html/QueryStringSpec.js +72 -0
- data/lib/jasmine-core/spec/html/ResultsNodeSpec.js +62 -0
- data/lib/jasmine-core/spec/html/SpyRegistryHtmlSpec.js +39 -0
- data/lib/jasmine-core/spec/html/matchers/toHaveClassSpec.js +48 -0
- data/lib/jasmine-core/spec/npmPackage/npmPackageSpec.js +101 -0
- data/lib/jasmine-core/spec/performance/large_object_test.js +36 -0
- data/lib/jasmine-core/spec/performance/performance_test.js +10 -0
- data/lib/jasmine-core/version.rb +1 -1
- metadata +88 -4
- data/lib/console/console.js +0 -190
@@ -0,0 +1,54 @@
|
|
1
|
+
describe("UserContext", function() {
|
2
|
+
it("Behaves just like an plain object", function() {
|
3
|
+
var context = new jasmineUnderTest.UserContext(),
|
4
|
+
properties = [];
|
5
|
+
|
6
|
+
for (var prop in context) {
|
7
|
+
if (obj.hasOwnProperty(prop)) {
|
8
|
+
properties.push(prop);
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
expect(properties).toEqual([]);
|
13
|
+
});
|
14
|
+
|
15
|
+
describe('.fromExisting', function() {
|
16
|
+
describe('when using an already built context as model', function() {
|
17
|
+
beforeEach(function() {
|
18
|
+
this.context = new jasmineUnderTest.UserContext();
|
19
|
+
this.context.key = 'value';
|
20
|
+
this.cloned = jasmineUnderTest.UserContext.fromExisting(this.context);
|
21
|
+
});
|
22
|
+
|
23
|
+
it('returns a cloned object', function() {
|
24
|
+
expect(this.cloned).toEqual(this.context);
|
25
|
+
});
|
26
|
+
|
27
|
+
it('does not return the same object', function() {
|
28
|
+
expect(this.cloned).not.toBe(this.context);
|
29
|
+
});
|
30
|
+
});
|
31
|
+
|
32
|
+
describe('when using a regular object as parameter', function() {
|
33
|
+
beforeEach(function() {
|
34
|
+
this.context = {};
|
35
|
+
this.value = 'value'
|
36
|
+
this.context.key = this.value;
|
37
|
+
this.cloned = jasmineUnderTest.UserContext.fromExisting(this.context);
|
38
|
+
});
|
39
|
+
|
40
|
+
it('returns an object with the same attributes', function() {
|
41
|
+
expect(this.cloned.key).toEqual(this.value);
|
42
|
+
});
|
43
|
+
|
44
|
+
it('does not return the same object', function() {
|
45
|
+
expect(this.cloned).not.toBe(this.context);
|
46
|
+
});
|
47
|
+
|
48
|
+
it('returns an UserContext', function() {
|
49
|
+
expect(this.cloned.constructor).toBe(jasmineUnderTest.UserContext);
|
50
|
+
});
|
51
|
+
});
|
52
|
+
});
|
53
|
+
});
|
54
|
+
|
@@ -0,0 +1,105 @@
|
|
1
|
+
describe("jasmineUnderTest.util", function() {
|
2
|
+
describe("isArray_", function() {
|
3
|
+
it("should return true if the argument is an array", function() {
|
4
|
+
expect(jasmineUnderTest.isArray_([])).toBe(true);
|
5
|
+
expect(jasmineUnderTest.isArray_(['a'])).toBe(true);
|
6
|
+
});
|
7
|
+
|
8
|
+
it("should return false if the argument is not an array", function() {
|
9
|
+
expect(jasmineUnderTest.isArray_(undefined)).toBe(false);
|
10
|
+
expect(jasmineUnderTest.isArray_({})).toBe(false);
|
11
|
+
expect(jasmineUnderTest.isArray_(function() {})).toBe(false);
|
12
|
+
expect(jasmineUnderTest.isArray_('foo')).toBe(false);
|
13
|
+
expect(jasmineUnderTest.isArray_(5)).toBe(false);
|
14
|
+
expect(jasmineUnderTest.isArray_(null)).toBe(false);
|
15
|
+
});
|
16
|
+
});
|
17
|
+
|
18
|
+
describe("isObject_", function() {
|
19
|
+
it("should return true if the argument is an object", function() {
|
20
|
+
expect(jasmineUnderTest.isObject_({})).toBe(true);
|
21
|
+
expect(jasmineUnderTest.isObject_({an: "object"})).toBe(true);
|
22
|
+
});
|
23
|
+
|
24
|
+
it("should return false if the argument is not an object", function() {
|
25
|
+
expect(jasmineUnderTest.isObject_(undefined)).toBe(false);
|
26
|
+
expect(jasmineUnderTest.isObject_([])).toBe(false);
|
27
|
+
expect(jasmineUnderTest.isObject_(function() {})).toBe(false);
|
28
|
+
expect(jasmineUnderTest.isObject_('foo')).toBe(false);
|
29
|
+
expect(jasmineUnderTest.isObject_(5)).toBe(false);
|
30
|
+
expect(jasmineUnderTest.isObject_(null)).toBe(false);
|
31
|
+
});
|
32
|
+
});
|
33
|
+
|
34
|
+
describe("isUndefined", function() {
|
35
|
+
it("reports if a variable is defined", function() {
|
36
|
+
var a;
|
37
|
+
expect(jasmineUnderTest.util.isUndefined(a)).toBe(true);
|
38
|
+
expect(jasmineUnderTest.util.isUndefined(undefined)).toBe(true);
|
39
|
+
|
40
|
+
var undefined = "diz be undefined yo";
|
41
|
+
expect(jasmineUnderTest.util.isUndefined(undefined)).toBe(false);
|
42
|
+
});
|
43
|
+
});
|
44
|
+
|
45
|
+
describe("getPropertyDescriptor", function() {
|
46
|
+
it("get property descriptor from object", function() {
|
47
|
+
var obj = {prop: 1},
|
48
|
+
actual = jasmineUnderTest.util.getPropertyDescriptor(obj, 'prop'),
|
49
|
+
expected = Object.getOwnPropertyDescriptor(obj, 'prop');
|
50
|
+
|
51
|
+
expect(actual).toEqual(expected);
|
52
|
+
});
|
53
|
+
|
54
|
+
it("get property descriptor from object property", function() {
|
55
|
+
var proto = {prop: 1},
|
56
|
+
obj = Object.create(proto),
|
57
|
+
actual = jasmineUnderTest.util.getPropertyDescriptor(proto, 'prop'),
|
58
|
+
expected = Object.getOwnPropertyDescriptor(proto, 'prop');
|
59
|
+
|
60
|
+
expect(actual).toEqual(expected);
|
61
|
+
});
|
62
|
+
});
|
63
|
+
|
64
|
+
describe("objectDifference", function() {
|
65
|
+
it("given two objects A and B, returns the properties in A not present in B", function() {
|
66
|
+
var a = {
|
67
|
+
foo: 3,
|
68
|
+
bar: 4,
|
69
|
+
baz: 5
|
70
|
+
};
|
71
|
+
|
72
|
+
var b = {
|
73
|
+
bar: 6,
|
74
|
+
quux: 7
|
75
|
+
};
|
76
|
+
|
77
|
+
expect(jasmineUnderTest.util.objectDifference(a, b)).toEqual({foo: 3, baz: 5})
|
78
|
+
});
|
79
|
+
|
80
|
+
it("only looks at own properties of both objects", function() {
|
81
|
+
function Foo() {}
|
82
|
+
|
83
|
+
Foo.prototype.x = 1;
|
84
|
+
Foo.prototype.y = 2;
|
85
|
+
|
86
|
+
var a = new Foo();
|
87
|
+
a.x = 1;
|
88
|
+
|
89
|
+
var b = new Foo();
|
90
|
+
b.y = 2;
|
91
|
+
|
92
|
+
expect(jasmineUnderTest.util.objectDifference(a, b)).toEqual({x: 1});
|
93
|
+
expect(jasmineUnderTest.util.objectDifference(b, a)).toEqual({y: 2});
|
94
|
+
});
|
95
|
+
});
|
96
|
+
|
97
|
+
describe("jasmineFile", function() {
|
98
|
+
it("returns the file containing jasmine.util", function() {
|
99
|
+
// Chrome sometimes reports foo.js as foo.js/, so tolerate
|
100
|
+
// a trailing slash if present.
|
101
|
+
expect(jasmineUnderTest.util.jasmineFile()).toMatch(/util.js\/?$/);
|
102
|
+
expect(jasmine.util.jasmineFile()).toMatch(/jasmine.js\/?$/);
|
103
|
+
});
|
104
|
+
});
|
105
|
+
});
|
@@ -0,0 +1,91 @@
|
|
1
|
+
describe("Any", function() {
|
2
|
+
it("matches a string", function() {
|
3
|
+
var any = new jasmineUnderTest.Any(String);
|
4
|
+
|
5
|
+
expect(any.asymmetricMatch("foo")).toBe(true);
|
6
|
+
});
|
7
|
+
|
8
|
+
it("matches a number", function() {
|
9
|
+
var any = new jasmineUnderTest.Any(Number);
|
10
|
+
|
11
|
+
expect(any.asymmetricMatch(1)).toBe(true);
|
12
|
+
});
|
13
|
+
|
14
|
+
it("matches a function", function() {
|
15
|
+
var any = new jasmineUnderTest.Any(Function);
|
16
|
+
|
17
|
+
expect(any.asymmetricMatch(function(){})).toBe(true);
|
18
|
+
});
|
19
|
+
|
20
|
+
it("matches an Object", function() {
|
21
|
+
var any = new jasmineUnderTest.Any(Object);
|
22
|
+
|
23
|
+
expect(any.asymmetricMatch({})).toBe(true);
|
24
|
+
});
|
25
|
+
|
26
|
+
it("matches a Boolean", function() {
|
27
|
+
var any = new jasmineUnderTest.Any(Boolean);
|
28
|
+
|
29
|
+
expect(any.asymmetricMatch(true)).toBe(true);
|
30
|
+
});
|
31
|
+
|
32
|
+
it("matches a Map", function() {
|
33
|
+
jasmine.getEnv().requireFunctioningMaps();
|
34
|
+
|
35
|
+
var any = new jasmineUnderTest.Any(Map);
|
36
|
+
|
37
|
+
expect(any.asymmetricMatch(new Map())).toBe(true);
|
38
|
+
});
|
39
|
+
|
40
|
+
it("matches a Set", function() {
|
41
|
+
jasmine.getEnv().requireFunctioningSets();
|
42
|
+
|
43
|
+
var any = new jasmineUnderTest.Any(Set);
|
44
|
+
|
45
|
+
expect(any.asymmetricMatch(new Set())).toBe(true);
|
46
|
+
});
|
47
|
+
|
48
|
+
it("matches a TypedArray", function() {
|
49
|
+
jasmine.getEnv().requireFunctioningTypedArrays();
|
50
|
+
|
51
|
+
var any = new jasmineUnderTest.Any(Uint32Array);
|
52
|
+
|
53
|
+
expect(any.asymmetricMatch(new Uint32Array([]))).toBe(true);
|
54
|
+
});
|
55
|
+
|
56
|
+
it("matches a Symbol", function() {
|
57
|
+
jasmine.getEnv().requireFunctioningSymbols();
|
58
|
+
|
59
|
+
var any = new jasmineUnderTest.Any(Symbol);
|
60
|
+
|
61
|
+
expect(any.asymmetricMatch(Symbol())).toBe(true);
|
62
|
+
});
|
63
|
+
|
64
|
+
it("matches another constructed object", function() {
|
65
|
+
var Thing = function() {},
|
66
|
+
any = new jasmineUnderTest.Any(Thing);
|
67
|
+
|
68
|
+
expect(any.asymmetricMatch(new Thing())).toBe(true);
|
69
|
+
});
|
70
|
+
|
71
|
+
it("does not treat null as an Object", function() {
|
72
|
+
var any = new jasmineUnderTest.Any(Object);
|
73
|
+
|
74
|
+
expect(any.asymmetricMatch(null)).toBe(false);
|
75
|
+
});
|
76
|
+
|
77
|
+
it("jasmineToString's itself", function() {
|
78
|
+
var any = new jasmineUnderTest.Any(Number);
|
79
|
+
|
80
|
+
expect(any.jasmineToString()).toEqual('<jasmine.any(Number)>');
|
81
|
+
expect(any.jasmineToString()).toEqual('<jasmine.any(Number)>');
|
82
|
+
});
|
83
|
+
|
84
|
+
describe("when called without an argument", function() {
|
85
|
+
it("tells the user to pass a constructor or use jasmine.anything()", function() {
|
86
|
+
expect(function() {
|
87
|
+
new jasmineUnderTest.Any();
|
88
|
+
}).toThrowError(TypeError, /constructor.*anything/);
|
89
|
+
});
|
90
|
+
});
|
91
|
+
});
|
@@ -0,0 +1,76 @@
|
|
1
|
+
describe("Anything", function() {
|
2
|
+
it("matches a string", function() {
|
3
|
+
var anything = new jasmineUnderTest.Anything();
|
4
|
+
|
5
|
+
expect(anything.asymmetricMatch('foo')).toBe(true);
|
6
|
+
});
|
7
|
+
|
8
|
+
it("matches a number", function() {
|
9
|
+
var anything = new jasmineUnderTest.Anything();
|
10
|
+
|
11
|
+
expect(anything.asymmetricMatch(42)).toBe(true);
|
12
|
+
});
|
13
|
+
|
14
|
+
it("matches an object", function() {
|
15
|
+
var anything = new jasmineUnderTest.Anything();
|
16
|
+
|
17
|
+
expect(anything.asymmetricMatch({ foo: 'bar' })).toBe(true);
|
18
|
+
});
|
19
|
+
|
20
|
+
it("matches an array", function() {
|
21
|
+
var anything = new jasmineUnderTest.Anything();
|
22
|
+
|
23
|
+
expect(anything.asymmetricMatch([1,2,3])).toBe(true);
|
24
|
+
});
|
25
|
+
|
26
|
+
it("matches a Map", function() {
|
27
|
+
jasmine.getEnv().requireFunctioningMaps();
|
28
|
+
|
29
|
+
var anything = new jasmineUnderTest.Anything();
|
30
|
+
|
31
|
+
expect(anything.asymmetricMatch(new Map())).toBe(true);
|
32
|
+
});
|
33
|
+
|
34
|
+
it("matches a Set", function() {
|
35
|
+
jasmine.getEnv().requireFunctioningSets();
|
36
|
+
|
37
|
+
var anything = new jasmineUnderTest.Anything();
|
38
|
+
|
39
|
+
expect(anything.asymmetricMatch(new Set())).toBe(true);
|
40
|
+
});
|
41
|
+
|
42
|
+
it("matches a TypedArray", function() {
|
43
|
+
jasmine.getEnv().requireFunctioningTypedArrays();
|
44
|
+
|
45
|
+
var anything = new jasmineUnderTest.Anything();
|
46
|
+
|
47
|
+
expect(anything.asymmetricMatch(new Uint32Array([]))).toBe(true);
|
48
|
+
});
|
49
|
+
|
50
|
+
it("matches a Symbol", function() {
|
51
|
+
jasmine.getEnv().requireFunctioningSymbols();
|
52
|
+
|
53
|
+
var anything = new jasmineUnderTest.Anything();
|
54
|
+
|
55
|
+
expect(anything.asymmetricMatch(Symbol())).toBe(true);
|
56
|
+
});
|
57
|
+
|
58
|
+
it("doesn't match undefined", function() {
|
59
|
+
var anything = new jasmineUnderTest.Anything();
|
60
|
+
|
61
|
+
expect(anything.asymmetricMatch()).toBe(false);
|
62
|
+
expect(anything.asymmetricMatch(undefined)).toBe(false);
|
63
|
+
});
|
64
|
+
|
65
|
+
it("doesn't match null", function() {
|
66
|
+
var anything = new jasmineUnderTest.Anything();
|
67
|
+
|
68
|
+
expect(anything.asymmetricMatch(null)).toBe(false);
|
69
|
+
});
|
70
|
+
|
71
|
+
it("jasmineToString's itself", function() {
|
72
|
+
var anything = new jasmineUnderTest.Anything();
|
73
|
+
|
74
|
+
expect(anything.jasmineToString()).toEqual("<jasmine.anything>");
|
75
|
+
});
|
76
|
+
});
|
@@ -0,0 +1,52 @@
|
|
1
|
+
describe("ArrayContaining", function() {
|
2
|
+
it("matches any actual to an empty array", function() {
|
3
|
+
var containing = new jasmineUnderTest.ArrayContaining([]);
|
4
|
+
|
5
|
+
expect(containing.asymmetricMatch("foo")).toBe(true);
|
6
|
+
});
|
7
|
+
|
8
|
+
it("does not work when not passed an array", function() {
|
9
|
+
var containing = new jasmineUnderTest.ArrayContaining("foo");
|
10
|
+
|
11
|
+
expect(function() {
|
12
|
+
containing.asymmetricMatch([]);
|
13
|
+
}).toThrowError(/not 'foo'/);
|
14
|
+
});
|
15
|
+
|
16
|
+
it("matches when the item is in the actual", function() {
|
17
|
+
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
|
18
|
+
|
19
|
+
expect(containing.asymmetricMatch(["foo"])).toBe(true);
|
20
|
+
});
|
21
|
+
|
22
|
+
it("matches when additional items are in the actual", function() {
|
23
|
+
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
|
24
|
+
|
25
|
+
expect(containing.asymmetricMatch(["foo", "bar"])).toBe(true);
|
26
|
+
});
|
27
|
+
|
28
|
+
it("does not match when the item is not in the actual", function() {
|
29
|
+
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
|
30
|
+
|
31
|
+
expect(containing.asymmetricMatch(["bar"])).toBe(false);
|
32
|
+
});
|
33
|
+
|
34
|
+
it("jasmineToStrings itself", function() {
|
35
|
+
var containing = new jasmineUnderTest.ArrayContaining([]);
|
36
|
+
|
37
|
+
expect(containing.jasmineToString()).toMatch("<jasmine.arrayContaining");
|
38
|
+
});
|
39
|
+
|
40
|
+
it("uses custom equality testers", function() {
|
41
|
+
var tester = function(a, b) {
|
42
|
+
// All "foo*" strings match each other.
|
43
|
+
if (typeof a == "string" && typeof b == "string" &&
|
44
|
+
a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
|
45
|
+
return true;
|
46
|
+
}
|
47
|
+
};
|
48
|
+
var containing = new jasmineUnderTest.ArrayContaining(["fooVal"]);
|
49
|
+
|
50
|
+
expect(containing.asymmetricMatch(["fooBar"], [tester])).toBe(true);
|
51
|
+
});
|
52
|
+
});
|
@@ -0,0 +1,47 @@
|
|
1
|
+
describe("ArrayWithExactContents", function() {
|
2
|
+
it("matches an array with the same items in a different order", function() {
|
3
|
+
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
|
4
|
+
|
5
|
+
expect(matcher.asymmetricMatch([2, 'a', /a/])).toBe(true);
|
6
|
+
});
|
7
|
+
|
8
|
+
it("does not work when not passed an array", function() {
|
9
|
+
var matcher = new jasmineUnderTest.ArrayWithExactContents("foo");
|
10
|
+
|
11
|
+
expect(function() {
|
12
|
+
matcher.asymmetricMatch([]);
|
13
|
+
}).toThrowError(/not 'foo'/);
|
14
|
+
});
|
15
|
+
|
16
|
+
it("does not match when an item is missing", function() {
|
17
|
+
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
|
18
|
+
|
19
|
+
expect(matcher.asymmetricMatch(['a', 2])).toBe(false);
|
20
|
+
expect(matcher.asymmetricMatch(['a', 2, undefined])).toBe(false);
|
21
|
+
});
|
22
|
+
|
23
|
+
it("does not match when there is an extra item", function() {
|
24
|
+
var matcher = new jasmineUnderTest.ArrayWithExactContents(['a']);
|
25
|
+
|
26
|
+
expect(matcher.asymmetricMatch(['a', 2])).toBe(false);
|
27
|
+
});
|
28
|
+
|
29
|
+
it("jasmineToStrings itself", function() {
|
30
|
+
var matcher = new jasmineUnderTest.ArrayWithExactContents([]);
|
31
|
+
|
32
|
+
expect(matcher.jasmineToString()).toMatch("<jasmine.arrayWithExactContents");
|
33
|
+
});
|
34
|
+
|
35
|
+
it("uses custom equality testers", function() {
|
36
|
+
var tester = function(a, b) {
|
37
|
+
// All "foo*" strings match each other.
|
38
|
+
if (typeof a == "string" && typeof b == "string" &&
|
39
|
+
a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
|
40
|
+
return true;
|
41
|
+
}
|
42
|
+
};
|
43
|
+
var matcher = new jasmineUnderTest.ArrayWithExactContents(["fooVal"]);
|
44
|
+
|
45
|
+
expect(matcher.asymmetricMatch(["fooBar"], [tester])).toBe(true);
|
46
|
+
});
|
47
|
+
});
|
@@ -0,0 +1,99 @@
|
|
1
|
+
describe("ObjectContaining", function() {
|
2
|
+
|
3
|
+
it("matches any actual to an empty object", function() {
|
4
|
+
var containing = new jasmineUnderTest.ObjectContaining({});
|
5
|
+
|
6
|
+
expect(containing.asymmetricMatch("foo")).toBe(true);
|
7
|
+
});
|
8
|
+
|
9
|
+
it("does not match an empty object actual", function() {
|
10
|
+
var containing = new jasmineUnderTest.ObjectContaining("foo");
|
11
|
+
|
12
|
+
expect(function() {
|
13
|
+
containing.asymmetricMatch({})
|
14
|
+
}).toThrowError(/not 'foo'/)
|
15
|
+
});
|
16
|
+
|
17
|
+
it("matches when the key/value pair is present in the actual", function() {
|
18
|
+
var containing = new jasmineUnderTest.ObjectContaining({foo: "fooVal"});
|
19
|
+
|
20
|
+
expect(containing.asymmetricMatch({foo: "fooVal", bar: "barVal"})).toBe(true);
|
21
|
+
});
|
22
|
+
|
23
|
+
it("does not match when the key/value pair is not present in the actual", function() {
|
24
|
+
var containing = new jasmineUnderTest.ObjectContaining({foo: "fooVal"});
|
25
|
+
|
26
|
+
expect(containing.asymmetricMatch({bar: "barVal", quux: "quuxVal"})).toBe(false);
|
27
|
+
});
|
28
|
+
|
29
|
+
it("does not match when the key is present but the value is different in the actual", function() {
|
30
|
+
var containing = new jasmineUnderTest.ObjectContaining({foo: "other"});
|
31
|
+
|
32
|
+
expect(containing.asymmetricMatch({foo: "fooVal", bar: "barVal"})).toBe(false);
|
33
|
+
});
|
34
|
+
|
35
|
+
it("jasmineToString's itself", function() {
|
36
|
+
var containing = new jasmineUnderTest.ObjectContaining({});
|
37
|
+
|
38
|
+
expect(containing.jasmineToString()).toMatch("<jasmine.objectContaining");
|
39
|
+
});
|
40
|
+
|
41
|
+
it("matches recursively", function() {
|
42
|
+
var containing = new jasmineUnderTest.ObjectContaining({one: new jasmineUnderTest.ObjectContaining({two: {}})});
|
43
|
+
|
44
|
+
expect(containing.asymmetricMatch({one: {two: {}}})).toBe(true);
|
45
|
+
});
|
46
|
+
|
47
|
+
it("matches when key is present with undefined value", function() {
|
48
|
+
var containing = new jasmineUnderTest.ObjectContaining({ one: undefined });
|
49
|
+
|
50
|
+
expect(containing.asymmetricMatch({ one: undefined })).toBe(true);
|
51
|
+
});
|
52
|
+
|
53
|
+
it("does not match when key with undefined value is not present", function() {
|
54
|
+
var containing = new jasmineUnderTest.ObjectContaining({ one: undefined });
|
55
|
+
|
56
|
+
expect(containing.asymmetricMatch({})).toBe(false);
|
57
|
+
});
|
58
|
+
|
59
|
+
it("matches defined properties", function(){
|
60
|
+
var containing = new jasmineUnderTest.ObjectContaining({ foo: "fooVal" });
|
61
|
+
|
62
|
+
var definedPropertyObject = {};
|
63
|
+
Object.defineProperty(definedPropertyObject, "foo", {
|
64
|
+
get: function() { return "fooVal" }
|
65
|
+
});
|
66
|
+
expect(containing.asymmetricMatch(definedPropertyObject)).toBe(true);
|
67
|
+
});
|
68
|
+
|
69
|
+
it("matches prototype properties", function(){
|
70
|
+
var containing = new jasmineUnderTest.ObjectContaining({ foo: "fooVal" });
|
71
|
+
|
72
|
+
var prototypeObject = {foo: "fooVal"};
|
73
|
+
var obj;
|
74
|
+
|
75
|
+
if (Object.create) {
|
76
|
+
obj = Object.create(prototypeObject);
|
77
|
+
} else {
|
78
|
+
function Foo() {}
|
79
|
+
Foo.prototype = prototypeObject;
|
80
|
+
Foo.prototype.constructor = Foo;
|
81
|
+
obj = new Foo();
|
82
|
+
}
|
83
|
+
|
84
|
+
expect(containing.asymmetricMatch(obj)).toBe(true);
|
85
|
+
});
|
86
|
+
|
87
|
+
it("uses custom equality testers", function() {
|
88
|
+
var tester = function(a, b) {
|
89
|
+
// All "foo*" strings match each other.
|
90
|
+
if (typeof a == "string" && typeof b == "string" &&
|
91
|
+
a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
|
92
|
+
return true;
|
93
|
+
}
|
94
|
+
};
|
95
|
+
var containing = new jasmineUnderTest.ObjectContaining({foo: "fooVal"});
|
96
|
+
|
97
|
+
expect(containing.asymmetricMatch({foo: "fooBar"}, [tester])).toBe(true);
|
98
|
+
});
|
99
|
+
});
|