Inject a per-runable pretty printer into MatchersUtil
This will allow us to add support for custom object formatters, which will be a per-runable resource like custom matchers, by injecting them into the pretty-printer.
This commit is contained in:
committed by
Steve Gravrock
parent
dec67bd535
commit
1f23f1e4d2
@@ -24,8 +24,9 @@ describe('AsyncExpectation', function() {
|
||||
|
||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = Promise.resolve(),
|
||||
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
util: new jasmineUnderTest.MatchersUtil(),
|
||||
util: new jasmineUnderTest.MatchersUtil({ pp: pp }),
|
||||
actual: actual,
|
||||
addExpectationResult: addExpectationResult
|
||||
});
|
||||
@@ -47,7 +48,7 @@ describe('AsyncExpectation', function() {
|
||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = Promise.reject(),
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
util: new jasmineUnderTest.MatchersUtil(),
|
||||
util: new jasmineUnderTest.MatchersUtil({ pp: function() {} }),
|
||||
actual: actual,
|
||||
addExpectationResult: addExpectationResult
|
||||
});
|
||||
@@ -122,7 +123,8 @@ describe('AsyncExpectation', function() {
|
||||
var util = {
|
||||
buildFailureMessage: function() {
|
||||
return 'failure message';
|
||||
}
|
||||
},
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
@@ -180,10 +182,11 @@ describe('AsyncExpectation', function() {
|
||||
|
||||
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
actual = Promise.resolve(),
|
||||
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
actual: actual,
|
||||
addExpectationResult: addExpectationResult,
|
||||
util: new jasmineUnderTest.MatchersUtil()
|
||||
util: new jasmineUnderTest.MatchersUtil({ pp: pp })
|
||||
});
|
||||
|
||||
return expectation
|
||||
@@ -208,7 +211,9 @@ describe('AsyncExpectation', function() {
|
||||
expectation = jasmineUnderTest.Expectation.asyncFactory({
|
||||
actual: actual,
|
||||
addExpectationResult: addExpectationResult,
|
||||
util: new jasmineUnderTest.MatchersUtil()
|
||||
util: new jasmineUnderTest.MatchersUtil({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
})
|
||||
});
|
||||
|
||||
return expectation
|
||||
|
||||
@@ -307,10 +307,12 @@ describe('Env', function() {
|
||||
|
||||
it('creates an expectationFactory that uses the current custom equality testers', function(done) {
|
||||
function customEqualityTester() {}
|
||||
function prettyPrinter() {}
|
||||
var RealSpec = jasmineUnderTest.Spec,
|
||||
specInstance,
|
||||
expectationFactory;
|
||||
spyOn(jasmineUnderTest, 'MatchersUtil');
|
||||
spyOn(jasmineUnderTest, 'makePrettyPrinter').and.returnValue(prettyPrinter);
|
||||
spyOn(jasmineUnderTest, 'Spec').and.callFake(function(options) {
|
||||
expectationFactory = options.expectationFactory;
|
||||
specInstance = new RealSpec(options);
|
||||
@@ -325,7 +327,8 @@ describe('Env', function() {
|
||||
env.addReporter({
|
||||
jasmineDone: function() {
|
||||
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
||||
customTesters: [customEqualityTester]
|
||||
customTesters: [customEqualityTester],
|
||||
pp: prettyPrinter
|
||||
});
|
||||
done();
|
||||
}
|
||||
@@ -336,10 +339,12 @@ describe('Env', function() {
|
||||
|
||||
it('creates an asyncExpectationFactory that uses the current custom equality testers', function(done) {
|
||||
function customEqualityTester() {}
|
||||
function prettyPrinter() {}
|
||||
var RealSpec = jasmineUnderTest.Spec,
|
||||
specInstance,
|
||||
asyncExpectationFactory;
|
||||
spyOn(jasmineUnderTest, 'MatchersUtil');
|
||||
spyOn(jasmineUnderTest, 'makePrettyPrinter').and.returnValue(prettyPrinter);
|
||||
spyOn(jasmineUnderTest, 'Spec').and.callFake(function(options) {
|
||||
asyncExpectationFactory = options.asyncExpectationFactory;
|
||||
specInstance = new RealSpec(options);
|
||||
@@ -354,7 +359,8 @@ describe('Env', function() {
|
||||
env.addReporter({
|
||||
jasmineDone: function() {
|
||||
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
|
||||
customTesters: [customEqualityTester]
|
||||
customTesters: [customEqualityTester],
|
||||
pp: prettyPrinter
|
||||
});
|
||||
done();
|
||||
}
|
||||
|
||||
@@ -632,9 +632,10 @@ describe('Expectation', function() {
|
||||
}
|
||||
},
|
||||
addExpectationResult = jasmine.createSpy('addExpectationResult'),
|
||||
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||
expectation = jasmineUnderTest.Expectation.factory({
|
||||
customMatchers: matchers,
|
||||
util: new jasmineUnderTest.MatchersUtil(),
|
||||
util: new jasmineUnderTest.MatchersUtil({ pp: pp }),
|
||||
actual: 'an actual',
|
||||
addExpectationResult: addExpectationResult
|
||||
});
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
describe('jasmineUnderTest.pp', function() {
|
||||
describe('PrettyPrinter', function() {
|
||||
it('should wrap strings in single quotes', function() {
|
||||
expect(jasmineUnderTest.pp('some string')).toEqual("'some string'");
|
||||
expect(jasmineUnderTest.pp("som' string")).toEqual("'som' string'");
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp('some string')).toEqual("'some string'");
|
||||
expect(pp("som' string")).toEqual("'som' string'");
|
||||
});
|
||||
|
||||
it('should stringify primitives properly', function() {
|
||||
expect(jasmineUnderTest.pp(true)).toEqual('true');
|
||||
expect(jasmineUnderTest.pp(false)).toEqual('false');
|
||||
expect(jasmineUnderTest.pp(null)).toEqual('null');
|
||||
expect(jasmineUnderTest.pp(jasmine.undefined)).toEqual('undefined');
|
||||
expect(jasmineUnderTest.pp(3)).toEqual('3');
|
||||
expect(jasmineUnderTest.pp(-3.14)).toEqual('-3.14');
|
||||
expect(jasmineUnderTest.pp(-0)).toEqual('-0');
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp(true)).toEqual('true');
|
||||
expect(pp(false)).toEqual('false');
|
||||
expect(pp(null)).toEqual('null');
|
||||
expect(pp(jasmine.undefined)).toEqual('undefined');
|
||||
expect(pp(3)).toEqual('3');
|
||||
expect(pp(-3.14)).toEqual('-3.14');
|
||||
expect(pp(-0)).toEqual('-0');
|
||||
});
|
||||
|
||||
describe('stringify sets', function() {
|
||||
@@ -20,7 +22,8 @@ describe('jasmineUnderTest.pp', function() {
|
||||
var set = new Set();
|
||||
set.add(1);
|
||||
set.add(2);
|
||||
expect(jasmineUnderTest.pp(set)).toEqual('Set( 1, 2 )');
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp(set)).toEqual('Set( 1, 2 )');
|
||||
});
|
||||
|
||||
it('should truncate sets with more elements than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH', function() {
|
||||
@@ -33,7 +36,8 @@ describe('jasmineUnderTest.pp', function() {
|
||||
set.add('a');
|
||||
set.add('b');
|
||||
set.add('c');
|
||||
expect(jasmineUnderTest.pp(set)).toEqual("Set( 'a', 'b', ... )");
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp(set)).toEqual("Set( 'a', 'b', ... )");
|
||||
} finally {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
|
||||
}
|
||||
@@ -45,7 +49,8 @@ describe('jasmineUnderTest.pp', function() {
|
||||
jasmine.getEnv().requireFunctioningMaps();
|
||||
var map = new Map();
|
||||
map.set(1, 2);
|
||||
expect(jasmineUnderTest.pp(map)).toEqual('Map( [ 1, 2 ] )');
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp(map)).toEqual('Map( [ 1, 2 ] )');
|
||||
});
|
||||
|
||||
it('should truncate maps with more elements than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH', function() {
|
||||
@@ -58,9 +63,8 @@ describe('jasmineUnderTest.pp', function() {
|
||||
map.set('a', 1);
|
||||
map.set('b', 2);
|
||||
map.set('c', 3);
|
||||
expect(jasmineUnderTest.pp(map)).toEqual(
|
||||
"Map( [ 'a', 1 ], [ 'b', 2 ], ... )"
|
||||
);
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp(map)).toEqual("Map( [ 'a', 1 ], [ 'b', 2 ], ... )");
|
||||
} finally {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
|
||||
}
|
||||
@@ -69,43 +73,44 @@ describe('jasmineUnderTest.pp', function() {
|
||||
|
||||
describe('stringify arrays', function() {
|
||||
it('should stringify arrays properly', function() {
|
||||
expect(jasmineUnderTest.pp([1, 2])).toEqual('[ 1, 2 ]');
|
||||
expect(
|
||||
jasmineUnderTest.pp([1, 'foo', {}, jasmine.undefined, null])
|
||||
).toEqual("[ 1, 'foo', Object({ }), undefined, null ]");
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp([1, 2])).toEqual('[ 1, 2 ]');
|
||||
expect(pp([1, 'foo', {}, jasmine.undefined, null])).toEqual(
|
||||
"[ 1, 'foo', Object({ }), undefined, null ]"
|
||||
);
|
||||
});
|
||||
|
||||
it('should truncate arrays that are longer than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH', function() {
|
||||
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||
var array = [1, 2, 3];
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||
expect(jasmineUnderTest.pp(array)).toEqual('[ 1, 2, ... ]');
|
||||
expect(pp(array)).toEqual('[ 1, 2, ... ]');
|
||||
} finally {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxLength;
|
||||
}
|
||||
});
|
||||
|
||||
it('should stringify arrays with properties properly', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var arr = [1, 2];
|
||||
arr.foo = 'bar';
|
||||
arr.baz = {};
|
||||
expect(jasmineUnderTest.pp(arr)).toEqual(
|
||||
"[ 1, 2, foo: 'bar', baz: Object({ }) ]"
|
||||
);
|
||||
expect(pp(arr)).toEqual("[ 1, 2, foo: 'bar', baz: Object({ }) ]");
|
||||
});
|
||||
|
||||
it('should stringify empty arrays with properties properly', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var empty = [];
|
||||
empty.foo = 'bar';
|
||||
empty.baz = {};
|
||||
expect(jasmineUnderTest.pp(empty)).toEqual(
|
||||
"[ foo: 'bar', baz: Object({ }) ]"
|
||||
);
|
||||
expect(pp(empty)).toEqual("[ foo: 'bar', baz: Object({ }) ]");
|
||||
});
|
||||
|
||||
it('should stringify long arrays with properties properly', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||
var long = [1, 2, 3];
|
||||
long.foo = 'bar';
|
||||
@@ -113,7 +118,7 @@ describe('jasmineUnderTest.pp', function() {
|
||||
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||
expect(jasmineUnderTest.pp(long)).toEqual(
|
||||
expect(pp(long)).toEqual(
|
||||
"[ 1, 2, ..., foo: 'bar', baz: Object({ }) ]"
|
||||
);
|
||||
} finally {
|
||||
@@ -122,26 +127,25 @@ describe('jasmineUnderTest.pp', function() {
|
||||
});
|
||||
|
||||
it('should indicate circular array references', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var array1 = [1, 2];
|
||||
var array2 = [array1];
|
||||
array1.push(array2);
|
||||
expect(jasmineUnderTest.pp(array1)).toEqual(
|
||||
'[ 1, 2, [ <circular reference: Array> ] ]'
|
||||
);
|
||||
expect(pp(array1)).toEqual('[ 1, 2, [ <circular reference: Array> ] ]');
|
||||
});
|
||||
|
||||
it('should not indicate circular references incorrectly', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var array = [[1]];
|
||||
expect(jasmineUnderTest.pp(array)).toEqual('[ [ 1 ] ]');
|
||||
expect(pp(array)).toEqual('[ [ 1 ] ]');
|
||||
});
|
||||
});
|
||||
|
||||
it('should stringify objects properly', function() {
|
||||
expect(jasmineUnderTest.pp({ foo: 'bar' })).toEqual(
|
||||
"Object({ foo: 'bar' })"
|
||||
);
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp({ foo: 'bar' })).toEqual("Object({ foo: 'bar' })");
|
||||
expect(
|
||||
jasmineUnderTest.pp({
|
||||
pp({
|
||||
foo: 'bar',
|
||||
baz: 3,
|
||||
nullValue: null,
|
||||
@@ -150,24 +154,24 @@ describe('jasmineUnderTest.pp', function() {
|
||||
).toEqual(
|
||||
"Object({ foo: 'bar', baz: 3, nullValue: null, undefinedValue: undefined })"
|
||||
);
|
||||
expect(jasmineUnderTest.pp({ foo: function() {}, bar: [1, 2, 3] })).toEqual(
|
||||
expect(pp({ foo: function() {}, bar: [1, 2, 3] })).toEqual(
|
||||
'Object({ foo: Function, bar: [ 1, 2, 3 ] })'
|
||||
);
|
||||
});
|
||||
|
||||
it('should stringify objects that almost look like DOM nodes', function() {
|
||||
expect(jasmineUnderTest.pp({ nodeType: 1 })).toEqual(
|
||||
'Object({ nodeType: 1 })'
|
||||
);
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp({ nodeType: 1 })).toEqual('Object({ nodeType: 1 })');
|
||||
});
|
||||
|
||||
it('should truncate objects with too many keys', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
||||
var long = { a: 1, b: 2, c: 3 };
|
||||
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
||||
expect(jasmineUnderTest.pp(long)).toEqual('Object({ a: 1, b: 2, ... })');
|
||||
expect(pp(long)).toEqual('Object({ a: 1, b: 2, ... })');
|
||||
} finally {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxLength;
|
||||
}
|
||||
@@ -185,12 +189,11 @@ describe('jasmineUnderTest.pp', function() {
|
||||
}
|
||||
|
||||
it('should truncate outputs that are too long', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var big = [{ a: 1, b: 'a long string' }, {}];
|
||||
|
||||
withMaxChars(34, function() {
|
||||
expect(jasmineUnderTest.pp(big)).toEqual(
|
||||
"[ Object({ a: 1, b: 'a long st ..."
|
||||
);
|
||||
expect(pp(big)).toEqual("[ Object({ a: 1, b: 'a long st ...");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -214,59 +217,55 @@ describe('jasmineUnderTest.pp', function() {
|
||||
jasmineToString: jasmine
|
||||
.createSpy('d jasmineToString')
|
||||
.and.returnValue('')
|
||||
};
|
||||
},
|
||||
pp = jasmineUnderTest.makePrettyPrinter();
|
||||
|
||||
withMaxChars(30, function() {
|
||||
jasmineUnderTest.pp([{ a: a, b: b, c: c }, d]);
|
||||
pp([{ a: a, b: b, c: c }, d]);
|
||||
expect(c.jasmineToString).not.toHaveBeenCalled();
|
||||
expect(d.jasmineToString).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it("should print 'null' as the constructor of an object with its own constructor property", function() {
|
||||
expect(jasmineUnderTest.pp({ constructor: function() {} })).toContain(
|
||||
'null({'
|
||||
);
|
||||
expect(jasmineUnderTest.pp({ constructor: 'foo' })).toContain('null({');
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp({ constructor: function() {} })).toContain('null({');
|
||||
expect(pp({ constructor: 'foo' })).toContain('null({');
|
||||
});
|
||||
|
||||
it('should not include inherited properties when stringifying an object', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var SomeClass = function SomeClass() {};
|
||||
SomeClass.prototype.foo = 'inherited foo';
|
||||
var instance = new SomeClass();
|
||||
instance.bar = 'my own bar';
|
||||
expect(jasmineUnderTest.pp(instance)).toEqual(
|
||||
"SomeClass({ bar: 'my own bar' })"
|
||||
);
|
||||
expect(pp(instance)).toEqual("SomeClass({ bar: 'my own bar' })");
|
||||
});
|
||||
|
||||
it('should not recurse objects and arrays more deeply than jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var originalMaxDepth = jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH;
|
||||
var nestedObject = { level1: { level2: { level3: { level4: 'leaf' } } } };
|
||||
var nestedArray = [1, [2, [3, [4, 'leaf']]]];
|
||||
|
||||
try {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = 2;
|
||||
expect(jasmineUnderTest.pp(nestedObject)).toEqual(
|
||||
expect(pp(nestedObject)).toEqual(
|
||||
'Object({ level1: Object({ level2: Object }) })'
|
||||
);
|
||||
expect(jasmineUnderTest.pp(nestedArray)).toEqual('[ 1, [ 2, Array ] ]');
|
||||
expect(pp(nestedArray)).toEqual('[ 1, [ 2, Array ] ]');
|
||||
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = 3;
|
||||
expect(jasmineUnderTest.pp(nestedObject)).toEqual(
|
||||
expect(pp(nestedObject)).toEqual(
|
||||
'Object({ level1: Object({ level2: Object({ level3: Object }) }) })'
|
||||
);
|
||||
expect(jasmineUnderTest.pp(nestedArray)).toEqual(
|
||||
'[ 1, [ 2, [ 3, Array ] ] ]'
|
||||
);
|
||||
expect(pp(nestedArray)).toEqual('[ 1, [ 2, [ 3, Array ] ] ]');
|
||||
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = 4;
|
||||
expect(jasmineUnderTest.pp(nestedObject)).toEqual(
|
||||
expect(pp(nestedObject)).toEqual(
|
||||
"Object({ level1: Object({ level2: Object({ level3: Object({ level4: 'leaf' }) }) }) })"
|
||||
);
|
||||
expect(jasmineUnderTest.pp(nestedArray)).toEqual(
|
||||
"[ 1, [ 2, [ 3, [ 4, 'leaf' ] ] ] ]"
|
||||
);
|
||||
expect(pp(nestedArray)).toEqual("[ 1, [ 2, [ 3, [ 4, 'leaf' ] ] ] ]");
|
||||
} finally {
|
||||
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = originalMaxDepth;
|
||||
}
|
||||
@@ -274,28 +273,32 @@ describe('jasmineUnderTest.pp', function() {
|
||||
|
||||
it('should stringify immutable circular objects', function() {
|
||||
if (Object.freeze) {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var frozenObject = { foo: { bar: 'baz' } };
|
||||
frozenObject.circular = frozenObject;
|
||||
frozenObject = Object.freeze(frozenObject);
|
||||
expect(jasmineUnderTest.pp(frozenObject)).toEqual(
|
||||
expect(pp(frozenObject)).toEqual(
|
||||
"Object({ foo: Object({ bar: 'baz' }), circular: <circular reference: Object> })"
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it('should stringify RegExp objects properly', function() {
|
||||
expect(jasmineUnderTest.pp(/x|y|z/)).toEqual('/x|y|z/');
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp(/x|y|z/)).toEqual('/x|y|z/');
|
||||
});
|
||||
|
||||
it('should indicate circular object references', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var sampleValue = { foo: 'hello' };
|
||||
sampleValue.nested = sampleValue;
|
||||
expect(jasmineUnderTest.pp(sampleValue)).toEqual(
|
||||
expect(pp(sampleValue)).toEqual(
|
||||
"Object({ foo: 'hello', nested: <circular reference: Object> })"
|
||||
);
|
||||
});
|
||||
|
||||
it('should indicate getters on objects as such', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var sampleValue = { id: 1 };
|
||||
if (sampleValue.__defineGetter__) {
|
||||
//not supported in IE!
|
||||
@@ -304,34 +307,38 @@ describe('jasmineUnderTest.pp', function() {
|
||||
});
|
||||
}
|
||||
if (sampleValue.__defineGetter__) {
|
||||
expect(jasmineUnderTest.pp(sampleValue)).toEqual(
|
||||
expect(pp(sampleValue)).toEqual(
|
||||
'Object({ id: 1, calculatedValue: <getter> })'
|
||||
);
|
||||
} else {
|
||||
expect(jasmineUnderTest.pp(sampleValue)).toEqual('Object({ id: 1 })');
|
||||
expect(pp(sampleValue)).toEqual('Object({ id: 1 })');
|
||||
}
|
||||
});
|
||||
|
||||
it('should not do HTML escaping of strings', function() {
|
||||
expect(jasmineUnderTest.pp('some <b>html string</b> &', false)).toEqual(
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp('some <b>html string</b> &', false)).toEqual(
|
||||
"'some <b>html string</b> &'"
|
||||
);
|
||||
});
|
||||
|
||||
it('should abbreviate the global (usually window) object', function() {
|
||||
expect(jasmineUnderTest.pp(jasmine.getGlobal())).toEqual('<global>');
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
expect(pp(jasmine.getGlobal())).toEqual('<global>');
|
||||
});
|
||||
|
||||
it('should stringify Date objects properly', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var now = new Date();
|
||||
expect(jasmineUnderTest.pp(now)).toEqual('Date(' + now.toString() + ')');
|
||||
expect(pp(now)).toEqual('Date(' + now.toString() + ')');
|
||||
});
|
||||
|
||||
it('should stringify spy objects properly', function() {
|
||||
var TestObject = {
|
||||
someFunction: function() {}
|
||||
},
|
||||
env = new jasmineUnderTest.Env();
|
||||
env = new jasmineUnderTest.Env(),
|
||||
pp = jasmineUnderTest.makePrettyPrinter();
|
||||
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() {
|
||||
@@ -343,20 +350,17 @@ describe('jasmineUnderTest.pp', function() {
|
||||
});
|
||||
|
||||
spyRegistry.spyOn(TestObject, 'someFunction');
|
||||
expect(jasmineUnderTest.pp(TestObject.someFunction)).toEqual(
|
||||
'spy on someFunction'
|
||||
);
|
||||
expect(pp(TestObject.someFunction)).toEqual('spy on someFunction');
|
||||
|
||||
expect(jasmineUnderTest.pp(env.createSpy('something'))).toEqual(
|
||||
'spy on something'
|
||||
);
|
||||
expect(pp(env.createSpy('something'))).toEqual('spy on something');
|
||||
});
|
||||
|
||||
it('should stringify spyOn toString properly', function() {
|
||||
var TestObject = {
|
||||
someFunction: function() {}
|
||||
},
|
||||
env = new jasmineUnderTest.Env();
|
||||
env = new jasmineUnderTest.Env(),
|
||||
pp = jasmineUnderTest.makePrettyPrinter();
|
||||
|
||||
var spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() {
|
||||
@@ -370,29 +374,29 @@ describe('jasmineUnderTest.pp', function() {
|
||||
spyRegistry.spyOn(TestObject, 'toString');
|
||||
var testSpyObj = env.createSpyObj('TheClassName', ['toString']);
|
||||
|
||||
expect(jasmineUnderTest.pp(testSpyObj)).toEqual(
|
||||
'spy on TheClassName.toString'
|
||||
);
|
||||
expect(pp(testSpyObj)).toEqual('spy on TheClassName.toString');
|
||||
});
|
||||
|
||||
it('should stringify objects that implement jasmineToString', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var obj = {
|
||||
jasmineToString: function() {
|
||||
return 'strung';
|
||||
}
|
||||
};
|
||||
|
||||
expect(jasmineUnderTest.pp(obj)).toEqual('strung');
|
||||
expect(pp(obj)).toEqual('strung');
|
||||
});
|
||||
|
||||
it('should stringify objects that implement custom toString', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var obj = {
|
||||
toString: function() {
|
||||
return 'my toString';
|
||||
}
|
||||
};
|
||||
|
||||
expect(jasmineUnderTest.pp(obj)).toEqual('my toString');
|
||||
expect(pp(obj)).toEqual('my toString');
|
||||
|
||||
// Simulate object from another global context (e.g. an iframe or Web Worker) that does not actually have a custom
|
||||
// toString despite obj.toString !== Object.prototype.toString
|
||||
@@ -403,20 +407,22 @@ describe('jasmineUnderTest.pp', function() {
|
||||
}
|
||||
};
|
||||
|
||||
expect(jasmineUnderTest.pp(objFromOtherContext)).toEqual(
|
||||
expect(pp(objFromOtherContext)).toEqual(
|
||||
"Object({ foo: 'bar', toString: Function })"
|
||||
);
|
||||
});
|
||||
|
||||
it("should stringify objects have have a toString that isn't a function", function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var obj = {
|
||||
toString: 'foo'
|
||||
};
|
||||
|
||||
expect(jasmineUnderTest.pp(obj)).toEqual("Object({ toString: 'foo' })");
|
||||
expect(pp(obj)).toEqual("Object({ toString: 'foo' })");
|
||||
});
|
||||
|
||||
it('should stringify objects from anonymous constructors with custom toString', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var MyAnonymousConstructor = (function() {
|
||||
return function() {};
|
||||
})();
|
||||
@@ -426,17 +432,19 @@ describe('jasmineUnderTest.pp', function() {
|
||||
|
||||
var a = new MyAnonymousConstructor();
|
||||
|
||||
expect(jasmineUnderTest.pp(a)).toEqual('<anonymous>({ })');
|
||||
expect(pp(a)).toEqual('<anonymous>({ })');
|
||||
});
|
||||
|
||||
it('should handle objects with null prototype', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var obj = Object.create(null);
|
||||
obj.foo = 'bar';
|
||||
|
||||
expect(jasmineUnderTest.pp(obj)).toEqual("null({ foo: 'bar' })");
|
||||
expect(pp(obj)).toEqual("null({ foo: 'bar' })");
|
||||
});
|
||||
|
||||
it('should gracefully handle objects with invalid toString implementations', function() {
|
||||
var pp = jasmineUnderTest.makePrettyPrinter();
|
||||
var obj = {
|
||||
foo: {
|
||||
toString: function() {
|
||||
@@ -466,7 +474,7 @@ describe('jasmineUnderTest.pp', function() {
|
||||
}
|
||||
};
|
||||
|
||||
expect(jasmineUnderTest.pp(obj)).toEqual(
|
||||
expect(pp(obj)).toEqual(
|
||||
'Object({ foo: [object Number], bar: [object Object], baz: 3, qux: Error: bar, baddy: has-invalid-toString-method })'
|
||||
);
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('passes when Error type matches', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.reject(new TypeError('foo'));
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('passes when Error type and message matches', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.reject(new TypeError('foo'));
|
||||
|
||||
@@ -32,7 +32,7 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('passes when Error matches and is exactly Error', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.reject(new Error());
|
||||
|
||||
@@ -48,7 +48,7 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('passes when Error message matches a string', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.reject(new Error('foo'));
|
||||
|
||||
@@ -63,7 +63,7 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('passes when Error message matches a RegExp', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.reject(new Error('foo'));
|
||||
|
||||
@@ -78,7 +78,7 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('passes when Error message is empty', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.reject(new Error());
|
||||
|
||||
@@ -93,7 +93,7 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('passes when no arguments', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.reject(new Error());
|
||||
|
||||
@@ -108,7 +108,7 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('fails when resolved', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.resolve(new Error('foo'));
|
||||
|
||||
@@ -123,7 +123,7 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('fails when rejected with non Error type', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.reject('foo');
|
||||
|
||||
@@ -138,7 +138,7 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('fails when Error type mismatches', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.reject(new Error('foo'));
|
||||
|
||||
@@ -153,7 +153,7 @@ describe('#toBeRejectedWithError', function () {
|
||||
it('fails when Error message mismatches', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = Promise.reject(new Error('foo'));
|
||||
|
||||
@@ -166,7 +166,7 @@ describe('#toBeRejectedWithError', function () {
|
||||
});
|
||||
|
||||
it('fails if actual is not a promise', function() {
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
|
||||
actual = 'not a promise';
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ describe('#toBeRejectedWith', function () {
|
||||
it('should fail if the promise is rejected with a different value', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||
actual = Promise.reject('A Bad Apple');
|
||||
|
||||
@@ -41,7 +41,7 @@ describe('#toBeRejectedWith', function () {
|
||||
it('should build its error correctly when negated', function () {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||
actual = Promise.reject(true);
|
||||
|
||||
@@ -67,7 +67,7 @@ describe('#toBeRejectedWith', function () {
|
||||
});
|
||||
|
||||
it('fails if actual is not a promise', function() {
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWith(matchersUtil),
|
||||
actual = 'not a promise';
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ describe('#toBeResolvedTo', function() {
|
||||
it('fails if the promise is rejected', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||
actual = Promise.reject('AsyncExpectationSpec error');
|
||||
|
||||
@@ -29,7 +29,7 @@ describe('#toBeResolvedTo', function() {
|
||||
it('fails if the promise is resolved to a different value', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||
actual = Promise.resolve({foo: 17});
|
||||
|
||||
@@ -44,7 +44,7 @@ describe('#toBeResolvedTo', function() {
|
||||
it('builds its message correctly when negated', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||
actual = Promise.resolve(true);
|
||||
|
||||
@@ -60,7 +60,10 @@ describe('#toBeResolvedTo', function() {
|
||||
jasmine.getEnv().requirePromises();
|
||||
|
||||
var customEqualityTesters = [function() { return true; }],
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: customEqualityTesters}),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({
|
||||
customTesters: customEqualityTesters,
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||
actual = Promise.resolve('actual');
|
||||
|
||||
@@ -70,7 +73,7 @@ describe('#toBeResolvedTo', function() {
|
||||
});
|
||||
|
||||
it('fails if actual is not a promise', function() {
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
|
||||
actual = 'not a promise';
|
||||
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
describe("matchersUtil", function() {
|
||||
it("exposes the injected pretty-printer as .pp", function() {
|
||||
var pp = function() {},
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: pp});
|
||||
|
||||
expect(matchersUtil.pp).toBe(pp);
|
||||
});
|
||||
|
||||
describe("equals", function() {
|
||||
it("passes for literals that are triple-equal", function() {
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
@@ -76,7 +83,7 @@ describe("matchersUtil", function() {
|
||||
});
|
||||
|
||||
it("fails for Arrays that have different lengths", function() {
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||
expect(matchersUtil.equals([1, 2], [1, 2, 3])).toBe(false);
|
||||
});
|
||||
|
||||
@@ -392,7 +399,7 @@ describe("matchersUtil", function() {
|
||||
|
||||
it("passes when a custom equality matcher passed to the constructor returns true", function() {
|
||||
var tester = function(a, b) { return true; },
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]});
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester], pp: function() {}});
|
||||
|
||||
expect(matchersUtil.equals(1, 2)).toBe(true);
|
||||
});
|
||||
@@ -416,7 +423,7 @@ describe("matchersUtil", function() {
|
||||
var tester = function(a, b) { return jasmine.undefined; };
|
||||
|
||||
it("passes for two empty Objects", function () {
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]});
|
||||
var matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester], pp: function() {}});
|
||||
expect(matchersUtil.equals({}, {})).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -431,7 +438,7 @@ describe("matchersUtil", function() {
|
||||
|
||||
it("fails for equivalents when a custom equality matcher passed to the constructor returns false", function() {
|
||||
var tester = function(a, b) { return false; },
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester]});
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [tester], pp: function() {}});
|
||||
|
||||
expect(matchersUtil.equals(1, 1)).toBe(false);
|
||||
});
|
||||
@@ -449,7 +456,7 @@ describe("matchersUtil", function() {
|
||||
it("passes for an asymmetric equality tester that returns true when a custom equality tester passed to the constructor return false", function() {
|
||||
var asymmetricTester = { asymmetricMatch: function(other) { return true; } },
|
||||
symmetricTester = function(a, b) { return false; },
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [symmetricTester()]});
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [symmetricTester()], pp: function() {}});
|
||||
|
||||
expect(matchersUtil.equals(asymmetricTester, true)).toBe(true);
|
||||
expect(matchersUtil.equals(true, asymmetricTester)).toBe(true);
|
||||
@@ -475,7 +482,7 @@ describe("matchersUtil", function() {
|
||||
it("is both a matchersUtil and the custom equality testers passed to the constructor", function() {
|
||||
var asymmetricTester = jasmine.createSpyObj('tester', ['asymmetricMatch']),
|
||||
symmetricTester = function() { } ,
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [symmetricTester]}),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [symmetricTester], pp: function() {}}),
|
||||
shim;
|
||||
|
||||
matchersUtil.equals(true, asymmetricTester);
|
||||
@@ -783,7 +790,7 @@ describe("matchersUtil", function() {
|
||||
|
||||
it("uses custom equality testers if passed to the constructor and actual is an Array", function() {
|
||||
var customTester = function(a, b) {return true;},
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [customTester]});
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: [customTester], pp: function() {}});
|
||||
|
||||
expect(matchersUtil.contains([1, 2], 3)).toBe(true);
|
||||
});
|
||||
@@ -838,7 +845,8 @@ describe("matchersUtil", function() {
|
||||
it("builds an English sentence for a failure case", function() {
|
||||
var actual = "foo",
|
||||
name = "toBar",
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: pp}),
|
||||
message = matchersUtil.buildFailureMessage(name, false, actual);
|
||||
|
||||
expect(message).toEqual("Expected 'foo' to bar.");
|
||||
@@ -848,7 +856,8 @@ describe("matchersUtil", function() {
|
||||
var actual = "foo",
|
||||
name = "toBar",
|
||||
isNot = true,
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: pp}),
|
||||
message = message = matchersUtil.buildFailureMessage(name, isNot, actual);
|
||||
|
||||
expect(message).toEqual("Expected 'foo' not to bar.");
|
||||
@@ -857,10 +866,22 @@ describe("matchersUtil", function() {
|
||||
it("builds an English sentence for an arbitrary array of expected arguments", function() {
|
||||
var actual = "foo",
|
||||
name = "toBar",
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||
pp = jasmineUnderTest.makePrettyPrinter(),
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: pp}),
|
||||
message = matchersUtil.buildFailureMessage(name, false, actual, "quux", "corge");
|
||||
|
||||
expect(message).toEqual("Expected 'foo' to bar 'quux', 'corge'.");
|
||||
});
|
||||
|
||||
it("uses the injected pretty-printer to format the expected", function() {
|
||||
var actual = "foo",
|
||||
name = "toBar",
|
||||
isNot = false,
|
||||
pp = function(value) { return '<' + value + '>'; },
|
||||
matchersUtil = new jasmineUnderTest.MatchersUtil({pp: pp}),
|
||||
message = message = matchersUtil.buildFailureMessage(name, isNot, actual);
|
||||
|
||||
expect(message).toEqual("Expected <foo> to bar.");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -10,7 +10,9 @@ describe('toBeInstanceOf', function() {
|
||||
});
|
||||
|
||||
it('passes for NaN', function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBeInstanceOf();
|
||||
var matcher = jasmineUnderTest.matchers.toBeInstanceOf({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
});
|
||||
var result = matcher.compare(NaN, Number);
|
||||
expect(result).toEqual({
|
||||
pass: true,
|
||||
@@ -156,7 +158,9 @@ describe('toBeInstanceOf', function() {
|
||||
it('passes for objects with no constructor', function() {
|
||||
var object = Object.create(null);
|
||||
|
||||
var matcher = jasmineUnderTest.matchers.toBeInstanceOf();
|
||||
var matcher = jasmineUnderTest.matchers.toBeInstanceOf({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
});
|
||||
var result = matcher.compare(object, Object);
|
||||
expect(result).toEqual({
|
||||
pass: true,
|
||||
@@ -219,7 +223,9 @@ describe('toBeInstanceOf', function() {
|
||||
});
|
||||
|
||||
it('raises an error if missing an expected value', function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBeInstanceOf();
|
||||
var matcher = jasmineUnderTest.matchers.toBeInstanceOf({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
});
|
||||
expect(function() {
|
||||
matcher.compare({}, undefined);
|
||||
}).toThrowError('<toBeInstanceOf> : Expected value is not a constructor function\n' +
|
||||
|
||||
@@ -29,7 +29,9 @@ describe("toBeNaN", function() {
|
||||
});
|
||||
|
||||
it("has a custom message on failure", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBeNaN(),
|
||||
var matcher = jasmineUnderTest.matchers.toBeNaN({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
result = matcher.compare(0);
|
||||
|
||||
expect(result.message()).toEqual("Expected 0 to be NaN.");
|
||||
|
||||
@@ -14,7 +14,9 @@ describe("toBeNegativeInfinity", function() {
|
||||
});
|
||||
|
||||
it("has a custom message on failure", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBeNegativeInfinity(),
|
||||
var matcher = jasmineUnderTest.matchers.toBeNegativeInfinity({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
result = matcher.compare(0);
|
||||
|
||||
expect(result.message()).toEqual("Expected 0 to be -Infinity.")
|
||||
|
||||
@@ -14,7 +14,9 @@ describe("toBePositiveInfinity", function() {
|
||||
});
|
||||
|
||||
it("has a custom message on failure", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toBePositiveInfinity(),
|
||||
var matcher = jasmineUnderTest.matchers.toBePositiveInfinity({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
result = matcher.compare(0);
|
||||
|
||||
expect(result.message()).toEqual("Expected 0 to be Infinity.")
|
||||
|
||||
@@ -9,7 +9,7 @@ describe("toBe", function() {
|
||||
});
|
||||
|
||||
it("passes with a custom message when expected is an array", function() {
|
||||
var util = new jasmineUnderTest.MatchersUtil(),
|
||||
var util = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.matchers.toBe(util),
|
||||
result,
|
||||
array = [1];
|
||||
@@ -20,7 +20,7 @@ describe("toBe", function() {
|
||||
});
|
||||
|
||||
it("passes with a custom message when expected is an object", function() {
|
||||
var util = new jasmineUnderTest.MatchersUtil(),
|
||||
var util = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.matchers.toBe(util),
|
||||
result,
|
||||
obj = {foo: "bar"};
|
||||
@@ -41,7 +41,7 @@ describe("toBe", function() {
|
||||
});
|
||||
|
||||
it("fails with a custom message when expected is an array", function() {
|
||||
var util = new jasmineUnderTest.MatchersUtil(),
|
||||
var util = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.matchers.toBe(util),
|
||||
result;
|
||||
|
||||
@@ -51,7 +51,7 @@ describe("toBe", function() {
|
||||
});
|
||||
|
||||
it("fails with a custom message when expected is an object", function() {
|
||||
var util = new jasmineUnderTest.MatchersUtil(),
|
||||
var util = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.matchers.toBe(util),
|
||||
result;
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@ describe("toEqual", function() {
|
||||
"use strict";
|
||||
|
||||
function compareEquals(actual, expected) {
|
||||
var util = new jasmineUnderTest.MatchersUtil(),
|
||||
var util = new jasmineUnderTest.MatchersUtil({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
matcher = jasmineUnderTest.matchers.toEqual(util);
|
||||
|
||||
var result = matcher.compare(actual, expected);
|
||||
@@ -103,8 +105,6 @@ describe("toEqual", function() {
|
||||
" g: 3\n" +
|
||||
"Expected $.x not to have properties\n" +
|
||||
" f: 4";
|
||||
|
||||
expect(compareEquals(actual, expected).message).toEqual(message);
|
||||
});
|
||||
|
||||
it("reports extra and missing properties of the root-level object", function() {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
describe("toHaveBeenCalledBefore", function() {
|
||||
it("throws an exception when the actual is not a spy", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
fn = function() {},
|
||||
secondSpy = new jasmineUnderTest.Env().createSpy('second spy');
|
||||
|
||||
@@ -8,7 +10,9 @@ describe("toHaveBeenCalledBefore", function() {
|
||||
});
|
||||
|
||||
it("throws an exception when the expected is not a spy", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
firstSpy = new jasmineUnderTest.Env().createSpy('first spy'),
|
||||
fn = function() {};
|
||||
|
||||
|
||||
@@ -21,7 +21,9 @@ describe("toHaveBeenCalled", function() {
|
||||
});
|
||||
|
||||
it("throws an exception when the actual is not a spy", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
fn = function() {};
|
||||
|
||||
expect(function() { matcher.compare(fn) }).toThrowError(Error, /Expected a spy, but got Function./);
|
||||
|
||||
@@ -49,7 +49,9 @@ describe("toHaveBeenCalledTimes", function() {
|
||||
});
|
||||
|
||||
it("throws an exception when the actual is not a spy", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
fn = function() {};
|
||||
|
||||
expect(function() {
|
||||
|
||||
@@ -2,7 +2,8 @@ describe("toHaveBeenCalledWith", function() {
|
||||
|
||||
it("passes when the actual was called with matching parameters", function() {
|
||||
var util = {
|
||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
|
||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(true),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
||||
calledSpy = new jasmineUnderTest.Env().createSpy('called-spy'),
|
||||
@@ -29,7 +30,8 @@ describe("toHaveBeenCalledWith", function() {
|
||||
|
||||
it("fails when the actual was not called", function() {
|
||||
var util = {
|
||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
|
||||
contains: jasmine.createSpy('delegated-contains').and.returnValue(false),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
||||
uncalledSpy = new jasmineUnderTest.Env().createSpy('uncalled spy'),
|
||||
@@ -41,7 +43,7 @@ describe("toHaveBeenCalledWith", function() {
|
||||
});
|
||||
|
||||
it("fails when the actual was called with different parameters", function() {
|
||||
var util = new jasmineUnderTest.MatchersUtil(),
|
||||
var util = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
|
||||
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
|
||||
calledSpy = new jasmineUnderTest.Env().createSpy('called spy'),
|
||||
result;
|
||||
@@ -71,8 +73,11 @@ describe("toHaveBeenCalledWith", function() {
|
||||
});
|
||||
|
||||
it("throws an exception when the actual is not a spy", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(),
|
||||
fn = function() {};
|
||||
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
fn = function () {
|
||||
};
|
||||
|
||||
expect(function() { matcher.compare(fn) }).toThrowError(/Expected a spy, but got Function./);
|
||||
});
|
||||
|
||||
@@ -27,7 +27,9 @@ describe('toHaveClass', function() {
|
||||
});
|
||||
|
||||
it('throws an exception when actual is not a DOM element', function() {
|
||||
var matcher = jasmineUnderTest.matchers.toHaveClass();
|
||||
var matcher = jasmineUnderTest.matchers.toHaveClass({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
matcher.compare('x', 'foo');
|
||||
|
||||
@@ -54,7 +54,9 @@ describe("toThrowError", function() {
|
||||
});
|
||||
|
||||
it("fails if thrown is not an instanceof Error", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
fn = function() {
|
||||
throw 4;
|
||||
},
|
||||
@@ -103,7 +105,9 @@ describe("toThrowError", function() {
|
||||
});
|
||||
|
||||
it("fails with the correct message if thrown is a falsy value", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
fn = function() {
|
||||
throw undefined;
|
||||
},
|
||||
@@ -128,7 +132,9 @@ describe("toThrowError", function() {
|
||||
});
|
||||
|
||||
it("passes if thrown is an Error and the expected is the same message", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
fn = function() {
|
||||
throw new Error("foo");
|
||||
},
|
||||
@@ -141,7 +147,9 @@ describe("toThrowError", function() {
|
||||
});
|
||||
|
||||
it("fails if thrown is an Error and the expected is not the same message", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
fn = function() {
|
||||
throw new Error("foo");
|
||||
},
|
||||
@@ -154,7 +162,9 @@ describe("toThrowError", function() {
|
||||
});
|
||||
|
||||
it("passes if thrown is an Error and the expected is a RegExp that matches the message", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
fn = function() {
|
||||
throw new Error("a long message");
|
||||
},
|
||||
@@ -167,7 +177,9 @@ describe("toThrowError", function() {
|
||||
});
|
||||
|
||||
it("fails if thrown is an Error and the expected is a RegExp that does not match the message", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
fn = function() {
|
||||
throw new Error("a long message");
|
||||
},
|
||||
@@ -232,9 +244,10 @@ describe("toThrowError", function() {
|
||||
|
||||
it("passes if thrown is a type of Error and it is equal to the expected Error and message", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(util),
|
||||
fn = function() {
|
||||
throw new TypeError("foo");
|
||||
},
|
||||
@@ -248,9 +261,10 @@ describe("toThrowError", function() {
|
||||
|
||||
it("passes if thrown is a custom error that takes arguments and it is equal to the expected custom error and message", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(util),
|
||||
CustomError = function CustomError(arg) { this.message = arg.message },
|
||||
fn = function() {
|
||||
throw new CustomError({message: "foo"});
|
||||
@@ -267,9 +281,10 @@ describe("toThrowError", function() {
|
||||
|
||||
it("fails if thrown is a type of Error and the expected is a different Error", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(util),
|
||||
fn = function() {
|
||||
throw new TypeError("foo");
|
||||
},
|
||||
@@ -283,9 +298,10 @@ describe("toThrowError", function() {
|
||||
|
||||
it("passes if thrown is a type of Error and has the same type as the expected Error and the message matches the expected message", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(util),
|
||||
fn = function() {
|
||||
throw new TypeError("foo");
|
||||
},
|
||||
@@ -299,9 +315,10 @@ describe("toThrowError", function() {
|
||||
|
||||
it("fails if thrown is a type of Error and the expected is a different Error", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
matcher = jasmineUnderTest.matchers.toThrowError(util),
|
||||
fn = function() {
|
||||
throw new TypeError("foo");
|
||||
},
|
||||
|
||||
@@ -32,7 +32,9 @@ describe("toThrowMatching", function() {
|
||||
});
|
||||
|
||||
it("fails with the correct message if thrown is a falsy value", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowMatching(),
|
||||
var matcher = jasmineUnderTest.matchers.toThrowMatching({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
fn = function() {
|
||||
throw undefined;
|
||||
},
|
||||
@@ -58,8 +60,10 @@ describe("toThrowMatching", function() {
|
||||
});
|
||||
|
||||
it("fails if the argument is a function that returns false when called with the error", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowMatching(),
|
||||
predicate = function(e) { return e.message === "oh no" },
|
||||
var matcher = jasmineUnderTest.matchers.toThrowMatching({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
predicate = function(e) { return e.message === "oh no" },
|
||||
fn = function() {
|
||||
throw new TypeError("nope");
|
||||
},
|
||||
|
||||
@@ -24,7 +24,8 @@ describe("toThrow", function() {
|
||||
|
||||
it("passes if it throws but there is no expected", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrow(util),
|
||||
fn = function() {
|
||||
@@ -39,7 +40,9 @@ describe("toThrow", function() {
|
||||
});
|
||||
|
||||
it("passes even if what is thrown is falsy", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrow(),
|
||||
var matcher = jasmineUnderTest.matchers.toThrow({
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
}),
|
||||
fn = function() {
|
||||
throw undefined;
|
||||
},
|
||||
@@ -52,7 +55,8 @@ describe("toThrow", function() {
|
||||
|
||||
it("passes if what is thrown is equivalent to what is expected", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(true),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrow(util),
|
||||
fn = function() {
|
||||
@@ -68,7 +72,8 @@ describe("toThrow", function() {
|
||||
|
||||
it("fails if what is thrown is not equivalent to what is expected", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrow(util),
|
||||
fn = function() {
|
||||
@@ -84,7 +89,8 @@ describe("toThrow", function() {
|
||||
|
||||
it("fails if what is thrown is not equivalent to undefined", function() {
|
||||
var util = {
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
|
||||
equals: jasmine.createSpy('delegated-equal').and.returnValue(false),
|
||||
pp: jasmineUnderTest.makePrettyPrinter()
|
||||
},
|
||||
matcher = jasmineUnderTest.matchers.toThrow(util),
|
||||
fn = function() {
|
||||
|
||||
Reference in New Issue
Block a user