Merge branch 'main' into 3.99

This commit is contained in:
Steve Gravrock
2020-09-14 18:39:32 -07:00
82 changed files with 2725 additions and 1286 deletions
+1
View File
@@ -1,3 +1,4 @@
/* eslint-disable compat/compat */
describe('AsyncExpectation', function() {
beforeEach(function() {
jasmineUnderTest.Expectation.addAsyncCoreMatchers(
+18 -26
View File
@@ -401,20 +401,16 @@ describe('Env', function() {
expectationFactory('actual', specInstance);
});
env.addReporter({
jasmineDone: function() {
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
customObjectFormatter
]);
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
customTesters: [customEqualityTester],
pp: prettyPrinter
});
done();
}
env.execute(null, function() {
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
customObjectFormatter
]);
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
customTesters: [customEqualityTester],
pp: prettyPrinter
});
done();
});
env.execute();
});
it('creates an asyncExpectationFactory that uses the current custom equality testers and object formatters', function(done) {
@@ -438,19 +434,15 @@ describe('Env', function() {
asyncExpectationFactory('actual', specInstance);
});
env.addReporter({
jasmineDone: function() {
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
customObjectFormatter
]);
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
customTesters: [customEqualityTester],
pp: prettyPrinter
});
done();
}
env.execute(null, function() {
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledWith([
customObjectFormatter
]);
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledWith({
customTesters: [customEqualityTester],
pp: prettyPrinter
});
done();
});
env.execute();
});
});
+2 -4
View File
@@ -29,8 +29,7 @@ describe('Exceptions:', function() {
done();
};
env.addReporter({ jasmineDone: expectations });
env.execute();
env.execute(null, expectations);
});
it('should handle exceptions thrown directly in top-level describe blocks and continue', function(done) {
@@ -53,7 +52,6 @@ describe('Exceptions:', function() {
done();
};
env.addReporter({ jasmineDone: expectations });
env.execute();
env.execute(null, expectations);
});
});
+18 -1
View File
@@ -58,7 +58,7 @@ describe('GlobalErrors', function() {
errors.pushListener(handler1);
errors.pushListener(handler2);
errors.popListener();
errors.popListener(handler2);
fakeGlobal.onerror('foo');
@@ -66,6 +66,23 @@ describe('GlobalErrors', function() {
expect(handler2).not.toHaveBeenCalled();
});
it('throws when no listener is passed to #popListener', function() {
var errors = new jasmineUnderTest.GlobalErrors({});
expect(function() {
errors.popListener();
}).toThrowError('popListener expects a listener');
});
it('throws when the argument to #popListener is not the current listener', function() {
var errors = new jasmineUnderTest.GlobalErrors({});
errors.pushListener(function() {});
expect(function() {
errors.popListener(function() {});
}).toThrowError(
'popListener was passed a different listener than the current one'
);
});
it('uninstalls itself, putting back a previous callback', function() {
var originalCallback = jasmine.createSpy('error'),
fakeGlobal = { onerror: originalCallback },
+4 -4
View File
@@ -19,7 +19,7 @@ describe('PrettyPrinter', function() {
describe('stringify sets', function() {
it('should stringify sets properly', function() {
jasmine.getEnv().requireFunctioningSets();
var set = new Set();
var set = new Set(); // eslint-disable-line compat/compat
set.add(1);
set.add(2);
var pp = jasmineUnderTest.makePrettyPrinter();
@@ -32,7 +32,7 @@ describe('PrettyPrinter', function() {
try {
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
var set = new Set();
var set = new Set(); // eslint-disable-line compat/compat
set.add('a');
set.add('b');
set.add('c');
@@ -47,7 +47,7 @@ describe('PrettyPrinter', function() {
describe('stringify maps', function() {
it('should stringify maps properly', function() {
jasmine.getEnv().requireFunctioningMaps();
var map = new Map();
var map = new Map(); // eslint-disable-line compat/compat
map.set(1, 2);
var pp = jasmineUnderTest.makePrettyPrinter();
expect(pp(map)).toEqual('Map( [ 1, 2 ] )');
@@ -59,7 +59,7 @@ describe('PrettyPrinter', function() {
try {
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
var map = new Map();
var map = new Map(); // eslint-disable-line compat/compat
map.set('a', 1);
map.set('b', 2);
map.set('c', 3);
+44
View File
@@ -512,6 +512,50 @@ describe('QueueRunner', function() {
expect(onExceptionCallback).toHaveBeenCalledWith('foo');
expect(queueableFn2.fn).toHaveBeenCalled();
});
it('issues a deprecation if the function also takes a parameter', function() {
var queueableFn = {
fn: function(done) {
return new StubPromise();
}
},
deprecated = jasmine.createSpy('deprecated'),
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn],
deprecated: deprecated
}),
env = jasmineUnderTest.getEnv();
queueRunner.execute();
expect(deprecated).toHaveBeenCalledWith(
'An asynchronous ' +
'before/it/after function took a done callback but also returned a ' +
'promise. This is not supported and will stop working in the future. ' +
'Either remove the done callback (recommended) or change the function ' +
'to not return a promise.'
);
});
it('issues a more specific deprecation if the function is `async`', function() {
jasmine.getEnv().requireAsyncAwait();
eval('var fn = async function(done){};');
var deprecated = jasmine.createSpy('deprecated'),
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [{ fn: fn }],
deprecated: deprecated
});
queueRunner.execute();
expect(deprecated).toHaveBeenCalledWith(
'An asynchronous ' +
'before/it/after function was defined with the async keyword but ' +
'also took a done callback. This is not supported and will stop ' +
'working in the future. Either remove the done callback ' +
'(recommended) or remove the async keyword.'
);
});
});
it('passes the error instance to exception handlers in HTML browsers', function() {
+32 -5
View File
@@ -227,7 +227,8 @@ describe('Spec', function() {
passedExpectations: [],
deprecationWarnings: [],
pendingReason: '',
duration: null
duration: jasmine.any(Number),
properties: null
},
'things'
);
@@ -273,8 +274,34 @@ describe('Spec', function() {
});
it('should report the duration of the test', function() {
var timer = jasmine.createSpyObj('timer', { start: null, elapsed: 77000 }),
spec = new jasmineUnderTest.Spec({
queueableFn: { fn: jasmine.createSpy('spec body') },
catchExceptions: function() {
return false;
},
resultCallback: function(result) {
duration = result.duration;
},
queueRunnerFactory: function(config) {
config.queueableFns.forEach(function(qf) {
qf.fn();
});
config.cleanupFns.forEach(function(qf) {
qf.fn();
});
config.onComplete();
},
timer: timer
}),
duration = undefined;
spec.execute(function() {});
expect(duration).toBe(77000);
});
it('should report properties set during the test', function() {
var done = jasmine.createSpy('done callback'),
timer = jasmine.createSpyObj('timer', { start: null, elapsed: 77000 }),
spec = new jasmineUnderTest.Spec({
queueableFn: { fn: jasmine.createSpy('spec body') },
catchExceptions: function() {
@@ -283,11 +310,11 @@ describe('Spec', function() {
resultCallback: function() {},
queueRunnerFactory: function(attrs) {
attrs.onComplete();
},
timer: timer
}
});
spec.setSpecProperty('a', 4);
spec.execute(done);
expect(spec.result.duration).toBe(77000);
expect(spec.result.properties).toEqual({ a: 4 });
});
it('#status returns passing by default', function() {
+69 -1
View File
@@ -70,7 +70,7 @@ describe('SpyStrategy', function() {
expect(originalFn).not.toHaveBeenCalled();
});
it('allows a non-Error to be thrown, wrapping it into an exception when executed', function() {
it('allows a string to be thrown, wrapping it into an exception when executed', function() {
var originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
@@ -82,6 +82,18 @@ describe('SpyStrategy', function() {
expect(originalFn).not.toHaveBeenCalled();
});
it('allows a non-Error to be thrown when executed', function() {
var originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy.throwError({ code: 'ESRCH' });
expect(function() {
spyStrategy.exec();
}).toThrow({ code: 'ESRCH' });
expect(originalFn).not.toHaveBeenCalled();
});
it('allows a fake function to be called instead', function() {
var originalFn = jasmine.createSpy('original'),
fakeFn = jasmine.createSpy('fake').and.returnValue(67),
@@ -140,6 +152,28 @@ describe('SpyStrategy', function() {
.catch(done.fail);
});
it('allows an empty resolved promise to be returned', function(done) {
jasmine.getEnv().requirePromises();
var originalFn = jasmine.createSpy('original'),
getPromise = function() {
return Promise;
},
spyStrategy = new jasmineUnderTest.SpyStrategy({
fn: originalFn,
getPromise: getPromise
});
spyStrategy.resolveTo();
spyStrategy
.exec()
.then(function(returnValue) {
expect(returnValue).toBe();
done();
})
.catch(done.fail);
});
it('fails if promises are not available', function() {
var originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
@@ -176,6 +210,29 @@ describe('SpyStrategy', function() {
.catch(done.fail);
});
it('allows an empty rejected promise to be returned', function(done) {
jasmine.getEnv().requirePromises();
var originalFn = jasmine.createSpy('original'),
getPromise = function() {
return Promise;
},
spyStrategy = new jasmineUnderTest.SpyStrategy({
fn: originalFn,
getPromise: getPromise
});
spyStrategy.rejectWith();
spyStrategy
.exec()
.then(done.fail)
.catch(function(error) {
expect(error).toBe();
done();
})
.catch(done.fail);
});
it('allows a non-Error to be rejected', function(done) {
jasmine.getEnv().requirePromises();
@@ -277,6 +334,17 @@ describe('SpyStrategy', function() {
}).toThrowError(/^Argument passed to callFake should be a function, got/);
});
it('allows generator functions to be passed to callFake strategy', function() {
jasmine.getEnv().requireGeneratorFunctions();
var generator = jasmine.getEnv().makeGeneratorFunction('yield "ok";'),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: function() {} });
spyStrategy.callFake(generator);
expect(spyStrategy.exec().next().value).toEqual('ok');
});
it('allows a return to plan stubbing after another strategy', function() {
var originalFn = jasmine.createSpy('original'),
fakeFn = jasmine.createSpy('fake').and.returnValue(67),
+1 -1
View File
@@ -40,7 +40,7 @@ describe('jasmineUnderTest.util', function() {
beforeEach(function() {
jasmine.getEnv().requirePromises();
mockNativePromise = new Promise(function(res, rej) {});
mockNativePromise = new Promise(function(res, rej) {}); // eslint-disable-line compat/compat
mockPromiseLikeObject = new mockPromiseLike();
});
@@ -63,7 +63,6 @@ describe('asymmetricEqualityTesterArgCompatShim', function() {
it('provides and deprecates properties of Array.prototype', function() {
var keys = [
'concat',
'constructor',
'every',
'filter',
'forEach',
@@ -82,8 +81,6 @@ describe('asymmetricEqualityTesterArgCompatShim', function() {
'some',
'sort',
'splice',
'toLocaleString',
'toString',
'unshift'
],
optionalKeys = [
@@ -142,4 +139,46 @@ describe('asymmetricEqualityTesterArgCompatShim', function() {
expect(deprecated).not.toHaveBeenCalled();
});
describe('When Array.prototype additions collide with MatchersUtil methods', function() {
function keys() {
return [
'contains',
'buildFailureMessage',
'asymmetricDiff_',
'asymmetricMatch_',
'equals',
'eq_'
];
}
beforeEach(function() {
keys().forEach(function(k) {
expect(Array.prototype[k])
.withContext('Array.prototype already had ' + k)
.toBeUndefined();
Array.prototype[k] = function() {};
});
});
afterEach(function() {
keys().forEach(function(k) {
delete Array.prototype[k];
});
});
it('uses the MatchersUtil methods', function() {
var matchersUtil = new jasmineUnderTest.MatchersUtil({}),
shim = jasmineUnderTest.asymmetricEqualityTesterArgCompatShim(
matchersUtil,
[]
);
keys().forEach(function(k) {
expect(shim[k])
.withContext(k + ' was overwritten')
.toBe(jasmineUnderTest.MatchersUtil.prototype[k]);
});
});
});
});
+6 -6
View File
@@ -34,7 +34,7 @@ describe("Any", function() {
var any = new jasmineUnderTest.Any(Map);
expect(any.asymmetricMatch(new Map())).toBe(true);
expect(any.asymmetricMatch(new Map())).toBe(true); // eslint-disable-line compat/compat
});
it("matches a Set", function() {
@@ -42,23 +42,23 @@ describe("Any", function() {
var any = new jasmineUnderTest.Any(Set);
expect(any.asymmetricMatch(new Set())).toBe(true);
expect(any.asymmetricMatch(new Set())).toBe(true); // eslint-disable-line compat/compat
});
it("matches a TypedArray", function() {
jasmine.getEnv().requireFunctioningTypedArrays();
var any = new jasmineUnderTest.Any(Uint32Array);
var any = new jasmineUnderTest.Any(Uint32Array); // eslint-disable-line compat/compat
expect(any.asymmetricMatch(new Uint32Array([]))).toBe(true);
expect(any.asymmetricMatch(new Uint32Array([]))).toBe(true); // eslint-disable-line compat/compat
});
it("matches a Symbol", function() {
jasmine.getEnv().requireFunctioningSymbols();
var any = new jasmineUnderTest.Any(Symbol);
var any = new jasmineUnderTest.Any(Symbol); // eslint-disable-line compat/compat
expect(any.asymmetricMatch(Symbol())).toBe(true);
expect(any.asymmetricMatch(Symbol())).toBe(true); // eslint-disable-line compat/compat
});
it("matches another constructed object", function() {
@@ -28,7 +28,7 @@ describe("Anything", function() {
var anything = new jasmineUnderTest.Anything();
expect(anything.asymmetricMatch(new Map())).toBe(true);
expect(anything.asymmetricMatch(new Map())).toBe(true); // eslint-disable-line compat/compat
});
it("matches a Set", function() {
@@ -36,7 +36,7 @@ describe("Anything", function() {
var anything = new jasmineUnderTest.Anything();
expect(anything.asymmetricMatch(new Set())).toBe(true);
expect(anything.asymmetricMatch(new Set())).toBe(true); // eslint-disable-line compat/compat
});
it("matches a TypedArray", function() {
@@ -44,7 +44,7 @@ describe("Anything", function() {
var anything = new jasmineUnderTest.Anything();
expect(anything.asymmetricMatch(new Uint32Array([]))).toBe(true);
expect(anything.asymmetricMatch(new Uint32Array([]))).toBe(true); // eslint-disable-line compat/compat
});
it("matches a Symbol", function() {
@@ -52,7 +52,7 @@ describe("Anything", function() {
var anything = new jasmineUnderTest.Anything();
expect(anything.asymmetricMatch(Symbol())).toBe(true);
expect(anything.asymmetricMatch(Symbol())).toBe(true); // eslint-disable-line compat/compat
});
it("doesn't match undefined", function() {
+6 -6
View File
@@ -24,20 +24,20 @@ describe("Empty", function () {
it("matches an empty map", function () {
jasmine.getEnv().requireFunctioningMaps();
var empty = new jasmineUnderTest.Empty();
var fullMap = new Map();
var fullMap = new Map(); // eslint-disable-line compat/compat
fullMap.set('thing', 2);
expect(empty.asymmetricMatch(new Map())).toBe(true);
expect(empty.asymmetricMatch(new Map())).toBe(true); // eslint-disable-line compat/compat
expect(empty.asymmetricMatch(fullMap)).toBe(false);
});
it("matches an empty set", function () {
jasmine.getEnv().requireFunctioningSets();
var empty = new jasmineUnderTest.Empty();
var fullSet = new Set();
var fullSet = new Set(); // eslint-disable-line compat/compat
fullSet.add(3);
expect(empty.asymmetricMatch(new Set())).toBe(true);
expect(empty.asymmetricMatch(new Set())).toBe(true); // eslint-disable-line compat/compat
expect(empty.asymmetricMatch(fullSet)).toBe(false);
});
@@ -45,7 +45,7 @@ describe("Empty", function () {
jasmine.getEnv().requireFunctioningTypedArrays();
var empty = new jasmineUnderTest.Empty();
expect(empty.asymmetricMatch(new Int16Array())).toBe(true);
expect(empty.asymmetricMatch(new Int16Array([1,2]))).toBe(false);
expect(empty.asymmetricMatch(new Int16Array())).toBe(true); // eslint-disable-line compat/compat
expect(empty.asymmetricMatch(new Int16Array([1,2]))).toBe(false); // eslint-disable-line compat/compat
});
});
@@ -1,3 +1,4 @@
/* eslint-disable compat/compat */
describe('MapContaining', function() {
function MapI(iterable) { // for IE11
var map = new Map();
@@ -24,9 +24,9 @@ describe("NotEmpty", function () {
it("matches a non empty map", function () {
jasmine.getEnv().requireFunctioningMaps();
var notEmpty = new jasmineUnderTest.NotEmpty();
var fullMap = new Map();
var fullMap = new Map(); // eslint-disable-line compat/compat
fullMap.set('one', 1);
var emptyMap = new Map();
var emptyMap = new Map(); // eslint-disable-line compat/compat
expect(notEmpty.asymmetricMatch(fullMap)).toBe(true);
expect(notEmpty.asymmetricMatch(emptyMap)).toBe(false);
@@ -35,9 +35,9 @@ describe("NotEmpty", function () {
it("matches a non empty set", function () {
jasmine.getEnv().requireFunctioningSets();
var notEmpty = new jasmineUnderTest.NotEmpty();
var filledSet = new Set();
var filledSet = new Set(); // eslint-disable-line compat/compat
filledSet.add(1);
var emptySet = new Set();
var emptySet = new Set(); // eslint-disable-line compat/compat
expect(notEmpty.asymmetricMatch(filledSet)).toBe(true);
expect(notEmpty.asymmetricMatch(emptySet)).toBe(false);
@@ -47,7 +47,7 @@ describe("NotEmpty", function () {
jasmine.getEnv().requireFunctioningTypedArrays();
var notEmpty = new jasmineUnderTest.NotEmpty();
expect(notEmpty.asymmetricMatch(new Int16Array([1,2,3]))).toBe(true);
expect(notEmpty.asymmetricMatch(new Int16Array())).toBe(false);
expect(notEmpty.asymmetricMatch(new Int16Array([1,2,3]))).toBe(true); // eslint-disable-line compat/compat
expect(notEmpty.asymmetricMatch(new Int16Array())).toBe(false); // eslint-disable-line compat/compat
});
});
@@ -149,7 +149,7 @@ describe("ObjectContaining", function() {
});
});
it("includes keys that are present in only sample", function() {
it("includes keys that are present only in sample", function() {
var sample = {a: 1, b: 2},
other = {a: 3},
containing = new jasmineUnderTest.ObjectContaining(sample),
@@ -1,3 +1,4 @@
/* eslint-disable compat/compat */
describe('SetContaining', function() {
function SetI(iterable) { // for IE11
var set = new Set();
+11
View File
@@ -51,4 +51,15 @@ describe('base helpers', function() {
expect(jasmineUnderTest.isAsymmetricEqualityTester_(obj)).toBe(true);
});
});
describe('isSet', function() {
it('returns true when the object is a Set', function() {
jasmine.getEnv().requireFunctioningSets();
expect(jasmineUnderTest.isSet(new Set())).toBe(true); // eslint-disable-line compat/compat
});
it('returns false when the object is not a Set', function() {
expect(jasmineUnderTest.isSet({})).toBe(false);
});
});
});
@@ -19,8 +19,8 @@ describe('Asymmetric equality testers (Integration)', function () {
.toBeUndefined();
};
env.addReporter({specDone: specExpectations, jasmineDone: done});
env.execute();
env.addReporter({specDone: specExpectations});
env.execute(null, done);
});
}
@@ -43,8 +43,8 @@ describe('Asymmetric equality testers (Integration)', function () {
.not.toEqual('');
};
env.addReporter({specDone: specExpectations, jasmineDone: done});
env.execute();
env.addReporter({specDone: specExpectations});
env.execute(null, done);
});
}
@@ -1,3 +1,4 @@
/* eslint-disable compat/compat */
describe('Custom Async Matchers (Integration)', function() {
var env;
@@ -27,8 +28,8 @@ describe('Custom Async Matchers (Integration)', function() {
expect(result.status).toEqual('passed');
};
env.addReporter({ specDone: specExpectations, jasmineDone: done });
env.execute();
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
});
it('uses the negative compare function for a negative comparison, if provided', function(done) {
@@ -51,8 +52,8 @@ describe('Custom Async Matchers (Integration)', function() {
expect(result.status).toEqual('passed');
};
env.addReporter({ specDone: specExpectations, jasmineDone: done });
env.execute();
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
});
it('generates messages with the same rules as built in matchers absent a custom message', function(done) {
@@ -76,8 +77,8 @@ describe('Custom Async Matchers (Integration)', function() {
expect(result.failedExpectations[0].message).toEqual("Expected 'a' to be real.");
};
env.addReporter({ specDone: specExpectations, jasmineDone: done });
env.execute();
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
});
it("passes the jasmine utility to the matcher factory", function (done) {
@@ -106,8 +107,8 @@ describe('Custom Async Matchers (Integration)', function() {
);
};
env.addReporter({specDone: specExpectations, jasmineDone: done});
env.execute();
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
});
// TODO: remove this in the next major release.
@@ -177,8 +178,8 @@ describe('Custom Async Matchers (Integration)', function() {
expect(result.failedExpectations).toEqual([]);
};
env.addReporter({ specDone: specExpectations, jasmineDone: done });
env.execute();
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
});
it('logs a deprecation once per matcher if the matcher factory takes two arguments', function (done) {
+20 -20
View File
@@ -37,9 +37,9 @@ describe("Custom Matchers (Integration)", function () {
expect(firstSpecResult.failedExpectations[0].message).toEqual("matcherForSpec: actual: zzz; expected: yyy");
done();
};
env.addReporter({ specDone:specDoneSpy, jasmineDone: expectations});
env.addReporter({ specDone:specDoneSpy });
env.execute();
env.execute(null, expectations);
});
it("passes the spec if the custom matcher passes", function(done) {
@@ -57,8 +57,8 @@ describe("Custom Matchers (Integration)", function () {
expect(result.status).toEqual('passed');
};
env.addReporter({ specDone: specExpectations, jasmineDone: done });
env.execute();
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
});
it("passes the spec if the custom equality matcher passes for types nested inside asymmetric equality testers", function(done) {
@@ -81,8 +81,8 @@ describe("Custom Matchers (Integration)", function () {
expect(result.status).toEqual('passed');
};
env.addReporter({ specDone: specExpectations, jasmineDone: done });
env.execute();
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
});
it("supports asymmetric equality testers that take a list of custom equality testers", function(done) {
@@ -112,8 +112,8 @@ describe("Custom Matchers (Integration)", function () {
expect(result.status).toEqual('passed');
};
env.addReporter({ specDone: specExpectations, jasmineDone: done });
env.execute();
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
});
it("displays an appropriate failure message if a custom equality matcher fails", function(done) {
@@ -139,8 +139,8 @@ describe("Custom Matchers (Integration)", function () {
);
};
env.addReporter({ specDone: specExpectations, jasmineDone: done });
env.execute();
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
});
it("uses the negative compare function for a negative comparison, if provided", function(done) {
@@ -161,8 +161,8 @@ describe("Custom Matchers (Integration)", function () {
expect(result.status).toEqual('passed');
};
env.addReporter({ specDone: specExpectations, jasmineDone: done });
env.execute();
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
});
it("generates messages with the same rules as built in matchers absent a custom message", function(done) {
@@ -184,8 +184,8 @@ describe("Custom Matchers (Integration)", function () {
expect(result.failedExpectations[0].message).toEqual("Expected 'a' to be real.");
};
env.addReporter({ specDone: specExpectations, jasmineDone: done });
env.execute();
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
});
it("passes the expected and actual arguments to the comparison function", function(done) {
@@ -209,8 +209,8 @@ describe("Custom Matchers (Integration)", function () {
expect(argumentSpy).toHaveBeenCalledWith(true, "arg1", "arg2");
};
env.addReporter({ specDone: specExpectations, jasmineDone: done });
env.execute();
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
});
it("passes the jasmine utility to the matcher factory", function (done) {
@@ -237,8 +237,8 @@ describe("Custom Matchers (Integration)", function () {
);
};
env.addReporter({specDone: specExpectations, jasmineDone: done});
env.execute();
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
});
// TODO: remove this in the next major release.
@@ -306,8 +306,8 @@ describe("Custom Matchers (Integration)", function () {
expect(result.failedExpectations).toEqual([]);
};
env.addReporter({specDone: specExpectations, jasmineDone: done});
env.execute();
env.addReporter({specDone: specExpectations});
env.execute(null, done);
});
it('logs a deprecation once per matcher if the matcher factory takes two arguments', function(done) {
@@ -25,9 +25,9 @@ describe("Custom object formatters", function() {
expect(specResults[1].failedExpectations[0].message).toEqual("Expected 42 to be undefined.");
done();
};
env.addReporter({ specDone:specDone, jasmineDone: expectations});
env.addReporter({ specDone:specDone });
env.execute();
env.execute(null, expectations);
});
it("scopes custom object formatters to a suite", function(done) {
@@ -54,9 +54,9 @@ describe("Custom object formatters", function() {
expect(specResults[1].failedExpectations[0].message).toEqual("Expected custom(42) to be undefined.");
done();
};
env.addReporter({ specDone:specDone, jasmineDone: expectations});
env.addReporter({ specDone:specDone });
env.execute();
env.execute(null, expectations);
});
it("throws an exception if you try to add a custom object formatter outside a runable", function() {
@@ -15,6 +15,7 @@ describe('Custom Spy Strategies (Integration)', function() {
.and.returnValue(42);
var strategy = jasmine.createSpy('custom strategy')
.and.returnValue(plan);
var jasmineDone = jasmine.createSpy('jasmineDone');
env.describe('suite defining a custom spy strategy', function() {
env.beforeEach(function() {
@@ -33,13 +34,14 @@ describe('Custom Spy Strategies (Integration)', function() {
expect(env.createSpy('something').and.frobnicate).toBeUndefined();
});
function jasmineDone(result) {
function expectations() {
var result = jasmineDone.calls.argsFor(0)[0];
expect(result.overallStatus).toEqual('passed');
done();
}
env.addReporter({ jasmineDone: jasmineDone });
env.execute();
env.execute(null, expectations);
});
it('allows adding more strategies local to a spec', function(done) {
@@ -47,6 +49,7 @@ describe('Custom Spy Strategies (Integration)', function() {
.and.returnValue(42);
var strategy = jasmine.createSpy('custom strategy')
.and.returnValue(plan);
var jasmineDone = jasmine.createSpy('jasmineDone');
env.it('spec defining a custom spy strategy', function() {
env.addSpyStrategy('frobnicate', strategy);
@@ -60,13 +63,14 @@ describe('Custom Spy Strategies (Integration)', function() {
expect(env.createSpy('something').and.frobnicate).toBeUndefined();
});
function jasmineDone(result) {
function expectations() {
var result = jasmineDone.calls.argsFor(0)[0];
expect(result.overallStatus).toEqual('passed');
done();
}
env.addReporter({ jasmineDone: jasmineDone });
env.execute();
env.execute(null, expectations);
});
it('allows using custom strategies on a per-argument basis', function(done) {
@@ -74,6 +78,7 @@ describe('Custom Spy Strategies (Integration)', function() {
.and.returnValue(42);
var strategy = jasmine.createSpy('custom strategy')
.and.returnValue(plan);
var jasmineDone = jasmine.createSpy('jasmineDone');
env.it('spec defining a custom spy strategy', function() {
env.addSpyStrategy('frobnicate', strategy);
@@ -91,13 +96,14 @@ describe('Custom Spy Strategies (Integration)', function() {
expect(env.createSpy('something').and.frobnicate).toBeUndefined();
});
function jasmineDone(result) {
function expectations() {
var result = jasmineDone.calls.argsFor(0)[0];
expect(result.overallStatus).toEqual('passed');
done();
}
env.addReporter({ jasmineDone: jasmineDone });
env.execute();
env.execute(null, expectations);
});
it('allows multiple custom strategies to be used', function(done) {
@@ -105,7 +111,9 @@ describe('Custom Spy Strategies (Integration)', function() {
strategy1 = jasmine.createSpy('strat 1').and.returnValue(plan1),
plan2 = jasmine.createSpy('plan 2').and.returnValue(24),
strategy2 = jasmine.createSpy('strat 2').and.returnValue(plan2),
specDone = jasmine.createSpy('specDone');
specDone = jasmine.createSpy('specDone'),
jasmineDone = jasmine.createSpy('jasmineDone');
env.beforeEach(function() {
env.addSpyStrategy('frobnicate', strategy1);
@@ -130,13 +138,14 @@ describe('Custom Spy Strategies (Integration)', function() {
expect(plan2).toHaveBeenCalled();
});
function jasmineDone(result) {
function expectations() {
var result = jasmineDone.calls.argsFor(0)[0];
expect(result.overallStatus).toEqual('passed');
expect(specDone.calls.count()).toBe(2);
done();
}
env.addReporter({ jasmineDone: jasmineDone, specDone: specDone });
env.execute();
env.execute(null, expectations);
});
});
@@ -29,13 +29,15 @@ describe('Default Spy Strategy (Integration)', function() {
expect(spy()).toBeUndefined();
});
function jasmineDone(result) {
function expectations() {
var result = jasmineDone.calls.argsFor(0)[0];
expect(result.overallStatus).toEqual('passed');
done();
}
var jasmineDone = jasmine.createSpy('jasmineDone');
env.addReporter({ jasmineDone: jasmineDone });
env.execute();
env.execute(null, expectations);
});
it('uses the default spy strategy defined when the spy is created', function (done) {
@@ -61,12 +63,14 @@ describe('Default Spy Strategy (Integration)', function() {
expect(d.and.isConfigured()).toBe(false);
});
function jasmineDone(result) {
function expectations() {
var result = jasmineDone.calls.argsFor(0)[0];
expect(result.overallStatus).toEqual('passed');
done();
}
var jasmineDone = jasmine.createSpy('jasmineDone');
env.addReporter({ jasmineDone: jasmineDone });
env.execute();
env.execute(null, expectations);
});
});
File diff suppressed because it is too large Load Diff
+56 -27
View File
@@ -28,8 +28,8 @@ describe('Matchers (Integration)', function() {
.toBeUndefined();
};
env.addReporter({ specDone: specExpectations, jasmineDone: done });
env.execute();
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
});
}
@@ -47,12 +47,15 @@ describe('Matchers (Integration)', function() {
expect(result.failedExpectations[0].message)
.withContext('Failed with a thrown error rather than a matcher failure')
.not.toMatch(/^Error: /);
expect(result.failedExpectations[0].message)
.withContext('Failed with a thrown type error rather than a matcher failure')
.not.toMatch(/^TypeError: /);
expect(result.failedExpectations[0].matcherName).withContext('Matcher name')
.not.toEqual('');
};
env.addReporter({ specDone: specExpectations, jasmineDone: done });
env.execute();
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
});
}
@@ -72,8 +75,8 @@ describe('Matchers (Integration)', function() {
.toEqual(config.expectedMessage);
};
env.addReporter({specDone: specExpectations, jasmineDone: done});
env.execute();
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
});
}
@@ -98,8 +101,8 @@ describe('Matchers (Integration)', function() {
.toBeUndefined();
};
env.addReporter({ specDone: specExpectations, jasmineDone: done });
env.execute();
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
});
}
@@ -123,8 +126,8 @@ describe('Matchers (Integration)', function() {
.not.toEqual('');
};
env.addReporter({ specDone: specExpectations, jasmineDone: done });
env.execute();
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
});
}
@@ -146,8 +149,8 @@ describe('Matchers (Integration)', function() {
.toEqual(config.expectedMessage);
};
env.addReporter({specDone: specExpectations, jasmineDone: done});
env.execute();
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
});
}
@@ -332,11 +335,11 @@ describe('Matchers (Integration)', function() {
describe('toBeResolved', function() {
verifyPassesAsync(function(env) {
return env.expectAsync(Promise.resolve()).toBeResolved();
return env.expectAsync(Promise.resolve()).toBeResolved(); // eslint-disable-line compat/compat
});
verifyFailsAsync(function(env) {
return env.expectAsync(Promise.reject()).toBeResolved();
return env.expectAsync(Promise.reject()).toBeResolved(); // eslint-disable-line compat/compat
});
});
@@ -345,11 +348,11 @@ describe('Matchers (Integration)', function() {
env.addCustomEqualityTester(function(a, b) {
return a.toString() === b.toString();
});
return env.expectAsync(Promise.resolve('5')).toBeResolvedTo(5);
return env.expectAsync(Promise.resolve('5')).toBeResolvedTo(5); // eslint-disable-line compat/compat
});
verifyFailsAsync(function(env) {
return env.expectAsync(Promise.resolve('foo')).toBeResolvedTo('bar');
return env.expectAsync(Promise.resolve('foo')).toBeResolvedTo('bar'); // eslint-disable-line compat/compat
});
verifyFailsWithCustomObjectFormattersAsync({
@@ -357,7 +360,7 @@ describe('Matchers (Integration)', function() {
return '|' + val + '|';
},
expectations: function(env) {
return env.expectAsync(Promise.resolve('x')).toBeResolvedTo('y');
return env.expectAsync(Promise.resolve('x')).toBeResolvedTo('y'); // eslint-disable-line compat/compat
},
expectedMessage: 'Expected a promise to be resolved to |y| ' +
'but it was resolved to |x|.'
@@ -366,11 +369,11 @@ describe('Matchers (Integration)', function() {
describe('toBeRejected', function() {
verifyPassesAsync(function(env) {
return env.expectAsync(Promise.reject('nope')).toBeRejected();
return env.expectAsync(Promise.reject('nope')).toBeRejected(); // eslint-disable-line compat/compat
});
verifyFailsAsync(function(env) {
return env.expectAsync(Promise.resolve()).toBeRejected();
return env.expectAsync(Promise.resolve()).toBeRejected(); // eslint-disable-line compat/compat
});
});
@@ -379,11 +382,11 @@ describe('Matchers (Integration)', function() {
env.addCustomEqualityTester(function(a, b) {
return a.toString() === b.toString();
});
return env.expectAsync(Promise.reject('5')).toBeRejectedWith(5);
return env.expectAsync(Promise.reject('5')).toBeRejectedWith(5); // eslint-disable-line compat/compat
});
verifyFailsAsync(function(env) {
return env.expectAsync(Promise.resolve()).toBeRejectedWith('nope');
return env.expectAsync(Promise.resolve()).toBeRejectedWith('nope'); // eslint-disable-line compat/compat
});
verifyFailsWithCustomObjectFormattersAsync({
@@ -391,7 +394,7 @@ describe('Matchers (Integration)', function() {
return '|' + val + '|';
},
expectations: function(env) {
return env.expectAsync(Promise.reject('x')).toBeRejectedWith('y');
return env.expectAsync(Promise.reject('x')).toBeRejectedWith('y'); // eslint-disable-line compat/compat
},
expectedMessage: 'Expected a promise to be rejected with |y| ' +
'but it was rejected with |x|.'
@@ -400,11 +403,11 @@ describe('Matchers (Integration)', function() {
describe('toBeRejectedWithError', function() {
verifyPassesAsync(function(env) {
return env.expectAsync(Promise.reject(new Error())).toBeRejectedWithError(Error);
return env.expectAsync(Promise.reject(new Error())).toBeRejectedWithError(Error); // eslint-disable-line compat/compat
});
verifyFailsAsync(function(env) {
return env.expectAsync(Promise.resolve()).toBeRejectedWithError(Error);
return env.expectAsync(Promise.resolve()).toBeRejectedWithError(Error); // eslint-disable-line compat/compat
});
verifyFailsWithCustomObjectFormattersAsync({
@@ -412,7 +415,7 @@ describe('Matchers (Integration)', function() {
return '|' + val + '|';
},
expectations: function(env) {
return env.expectAsync(Promise.reject('foo')).toBeRejectedWithError('foo');
return env.expectAsync(Promise.reject('foo')).toBeRejectedWithError('foo'); // eslint-disable-line compat/compat
},
expectedMessage: 'Expected a promise to be rejected with Error: |foo| ' +
'but it was rejected with |foo|.'
@@ -477,9 +480,9 @@ describe('Matchers (Integration)', function() {
verifyFailsWithCustomObjectFormatters({
formatter: function(val) {
if (val === 5) {
return "five"
return 'five';
} else if (val === 4) {
return "four"
return 'four';
}
},
expectations: function(env) {
@@ -489,6 +492,16 @@ describe('Matchers (Integration)', function() {
});
});
describe('toHaveSize', function() {
verifyPasses(function(env) {
env.expect(['a','b']).toHaveSize(2);
});
verifyFails(function(env) {
env.expect(['a','b']).toHaveSize(1);
});
});
describe('toHaveBeenCalled', function() {
verifyPasses(function(env) {
var spy = env.createSpy('spy');
@@ -560,6 +573,22 @@ describe('Matchers (Integration)', function() {
});
});
describe('toHaveBeenCalledOnceWith', function() {
verifyPasses(function(env) {
var spy = env.createSpy();
spy('5', 3);
env.addCustomEqualityTester(function(a, b) {
return a.toString() === b.toString();
});
env.expect(spy).toHaveBeenCalledOnceWith(5, 3);
});
verifyFails(function(env) {
var spy = env.createSpy();
env.expect(spy).toHaveBeenCalledOnceWith(5, 3);
});
});
describe('toHaveClass', function() {
beforeEach(function() {
this.domHelpers = jasmine.getEnv().domHelpers();
+59 -159
View File
@@ -66,17 +66,14 @@ describe("spec running", function () {
expect(bar).toEqual(0);
expect(baz).toEqual(0);
expect(quux).toEqual(0);
var assertions = function() {
env.execute(null, function() {
expect(foo).toEqual(1);
expect(bar).toEqual(1);
expect(baz).toEqual(1);
expect(quux).toEqual(1);
done();
};
env.addReporter({ jasmineDone: assertions });
env.execute();
});
});
it("should permit nested describes", function(done) {
@@ -136,7 +133,7 @@ describe("spec running", function () {
});
});
var assertions = function() {
env.execute(null, function() {
var expected = [
"topSuite beforeEach",
"outer beforeEach",
@@ -168,11 +165,7 @@ describe("spec running", function () {
];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
it("should run multiple befores and afters ordered so functions declared later are treated as more specific", function(done) {
@@ -232,7 +225,7 @@ describe("spec running", function () {
});
});
var assertions = function() {
env.execute(null, function() {
var expected = [
"runner beforeAll1",
"runner beforeAll2",
@@ -250,11 +243,7 @@ describe("spec running", function () {
];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
it('should run beforeAlls before beforeEachs and afterAlls after afterEachs', function(done) {
@@ -298,7 +287,7 @@ describe("spec running", function () {
});
});
var assertions = function() {
env.execute(null, function() {
var expected = [
"runner beforeAll",
"inner beforeAll",
@@ -312,10 +301,7 @@ describe("spec running", function () {
];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
it('should run beforeAlls and afterAlls in the order declared when runnablesToRun is provided', function(done) {
@@ -365,7 +351,7 @@ describe("spec running", function () {
});
});
var assertions = function() {
env.execute([spec2.id, spec.id], function() {
var expected = [
"runner beforeAll",
"inner beforeAll",
@@ -385,10 +371,7 @@ describe("spec running", function () {
];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute([spec2.id, spec.id]);
});
});
it('only runs *Alls once in a focused suite', function(done){
@@ -406,13 +389,10 @@ describe("spec running", function () {
});
});
var assertions = function() {
env.execute(null, function() {
expect(actions).toEqual(['beforeAll', 'spec', 'afterAll']);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
describe('focused runnables', function() {
@@ -435,7 +415,7 @@ describe("spec running", function () {
});
});
var assertions = function() {
env.execute(null, function() {
var expected = [
'beforeAll',
'beforeEach',
@@ -449,10 +429,7 @@ describe("spec running", function () {
];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
it('focused specs in focused suites cause non-focused siblings to not run', function(done){
@@ -467,14 +444,11 @@ describe("spec running", function () {
});
});
var assertions = function() {
env.execute(null, function() {
var expected = ['focused spec'];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
it('focused suites in focused suites cause non-focused siblings to not run', function(done){
@@ -491,14 +465,11 @@ describe("spec running", function () {
});
});
var assertions = function() {
env.execute(null, function() {
var expected = ['inner spec'];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
it('focused runnables unfocus ancestor focused suites', function(done) {
@@ -515,14 +486,11 @@ describe("spec running", function () {
});
});
var assertions = function() {
env.execute(null, function() {
var expected = ['focused spec'];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
});
@@ -534,14 +502,10 @@ describe("spec running", function () {
});
});
var assertions = function() {
env.execute(null, function() {
expect(specInADisabledSuite).not.toHaveBeenCalled();
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
it("shouldn't run before/after functions in disabled suites", function(done) {
@@ -556,14 +520,10 @@ describe("spec running", function () {
env.it('spec inside a disabled suite', shouldNotRun);
});
var assertions = function() {
env.execute(null, function() {
expect(shouldNotRun).not.toHaveBeenCalled();
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
it("should allow top level suites to be disabled", function(done) {
@@ -577,15 +537,11 @@ describe("spec running", function () {
env.it('another spec', otherSpec);
});
var assertions = function() {
env.execute(null, function() {
expect(specInADisabledSuite).not.toHaveBeenCalled();
expect(otherSpec).toHaveBeenCalled();
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
it("should set all pending specs to pending when a suite is run", function(done) {
@@ -594,31 +550,20 @@ describe("spec running", function () {
pendingSpec = env.it("I am a pending spec");
});
var assertions = function() {
env.execute(null, function() {
expect(pendingSpec.status()).toBe("pending");
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
it("should recover gracefully when there are errors in describe functions", function(done) {
var specs = [],
reporter = jasmine.createSpyObj(['specDone', 'suiteDone', 'jasmineDone']);
reporter = jasmine.createSpyObj(['specDone', 'suiteDone']);
reporter.specDone.and.callFake(function(result) {
specs.push(result.fullName);
});
reporter.jasmineDone.and.callFake(function() {
expect(specs).toEqual(['outer1 inner1 should thingy', 'outer1 inner2 should other thingy', 'outer2 should xxx']);
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer1 inner1', [/inner error/]);
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer1', [/outer error/]);
done();
});
expect(function() {
env.describe("outer1", function() {
env.describe("inner1", function() {
@@ -647,7 +592,12 @@ describe("spec running", function () {
});
env.addReporter(reporter);
env.execute();
env.execute(null, function() {
expect(specs).toEqual(['outer1 inner1 should thingy', 'outer1 inner2 should other thingy', 'outer2 should xxx']);
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer1 inner1', [/inner error/]);
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer1', [/outer error/]);
done();
});
});
it("re-enters suites that have no *Alls", function(done) {
@@ -668,14 +618,10 @@ describe("spec running", function () {
actions.push("spec3");
});
env.addReporter({
jasmineDone: function() {
expect(actions).toEqual(["spec2", "spec3", "spec1"]);
done();
}
env.execute([spec2.id, spec3.id, spec1.id], function() {
expect(actions).toEqual(["spec2", "spec3", "spec1"]);
done();
});
env.execute([spec2.id, spec3.id, spec1.id]);
});
it("refuses to re-enter suites with a beforeAll", function() {
@@ -698,16 +644,10 @@ describe("spec running", function () {
actions.push("spec3");
});
env.addReporter({
jasmineDone: function() {
expect(actions).toEqual([]);
done();
}
});
expect(function() {
env.execute([spec2.id, spec3.id, spec1.id]);
}).toThrowError(/beforeAll/);
expect(actions).toEqual([]);
});
it("refuses to re-enter suites with a afterAll", function() {
@@ -730,16 +670,10 @@ describe("spec running", function () {
actions.push("spec3");
});
env.addReporter({
jasmineDone: function() {
expect(actions).toEqual([]);
done();
}
});
expect(function() {
env.execute([spec2.id, spec3.id, spec1.id]);
}).toThrowError(/afterAll/);
expect(actions).toEqual([]);
});
it("should run the tests in a consistent order when a seed is supplied", function(done) {
@@ -800,7 +734,7 @@ describe("spec running", function () {
});
});
var assertions = function() {
env.execute(null, function() {
var expected = [
'topSuite beforeEach',
'outer beforeEach',
@@ -832,11 +766,7 @@ describe("spec running", function () {
];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
describe("When throwOnExpectationFailure is set", function() {
@@ -870,18 +800,14 @@ describe("spec running", function () {
env.configure({oneFailurePerSpec: true});
var assertions = function() {
env.execute(null, function() {
expect(actions).toEqual([
'outer beforeEach',
'inner afterEach',
'outer afterEach'
]);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
it("skips to cleanup functions after done.fail is called", function(done) {
@@ -905,17 +831,13 @@ describe("spec running", function () {
env.configure({oneFailurePerSpec: true});
var assertions = function() {
env.execute(null, function() {
expect(actions).toEqual([
'beforeEach',
'afterEach'
]);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
it("skips to cleanup functions when an async function times out", function(done) {
@@ -937,17 +859,13 @@ describe("spec running", function () {
env.configure({oneFailurePerSpec: true});
var assertions = function() {
env.execute(null, function() {
expect(actions).toEqual([
'beforeEach',
'afterEach'
]);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
it("skips to cleanup functions after an error with deprecations", function(done) {
@@ -982,7 +900,7 @@ describe("spec running", function () {
env.throwOnExpectationFailure(true);
var assertions = function() {
env.execute(null, function() {
expect(actions).toEqual([
'outer beforeEach',
'inner afterEach',
@@ -990,11 +908,7 @@ describe("spec running", function () {
]);
expect(env.deprecated).toHaveBeenCalled();
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
it("skips to cleanup functions after done.fail is called with deprecations", function(done) {
@@ -1020,18 +934,14 @@ describe("spec running", function () {
env.throwOnExpectationFailure(true);
var assertions = function() {
env.execute(null, function() {
expect(actions).toEqual([
'beforeEach',
'afterEach'
]);
expect(env.deprecated).toHaveBeenCalled();
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
it("skips to cleanup functions when an async function times out with deprecations", function(done) {
@@ -1055,18 +965,14 @@ describe("spec running", function () {
env.throwOnExpectationFailure(true);
var assertions = function() {
env.execute(null, function() {
expect(actions).toEqual([
'beforeEach',
'afterEach'
]);
expect(env.deprecated).toHaveBeenCalled();
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
});
@@ -1089,13 +995,10 @@ describe("spec running", function () {
env.configure({random: false, failFast: true});
var assertions = function() {
env.execute(null, function() {
expect(actions).toEqual(['fails']);
done();
};
env.addReporter({ jasmineDone: assertions });
env.execute();
});
});
it("does not run further specs when one fails when configured with deprecated option", function(done) {
@@ -1119,14 +1022,11 @@ describe("spec running", function () {
env.configure({random: false});
env.stopOnSpecFailure(true);
var assertions = function() {
env.execute(null, function() {
expect(actions).toEqual(['fails']);
expect(env.deprecated).toHaveBeenCalled();
done();
};
env.addReporter({ jasmineDone: assertions });
env.execute();
});
});
});
});
+46
View File
@@ -133,4 +133,50 @@ describe("DiffBuilder", function () {
expect(diffBuilder.getMessage()).toEqual(expectedMsg);
});
it('builds diffs involving asymmetric equality testers that implement valuesForDiff_ at the root', function() {
var prettyPrinter = jasmineUnderTest.makePrettyPrinter([]),
diffBuilder = new jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter}),
expectedMsg = 'Expected $.foo = 1 to equal 2.\n' +
"Expected $.baz = undefined to equal 3.";
diffBuilder.setRoots(
{foo: 1, bar: 2},
jasmine.objectContaining({foo: 2, baz: 3})
);
diffBuilder.withPath('foo', function() {
diffBuilder.recordMismatch();
});
diffBuilder.withPath('baz', function() {
diffBuilder.recordMismatch();
});
expect(diffBuilder.getMessage()).toEqual(expectedMsg);
});
it('builds diffs involving asymmetric equality testers that implement valuesForDiff_ below the root', function() {
var prettyPrinter = jasmineUnderTest.makePrettyPrinter([]),
diffBuilder = new jasmineUnderTest.DiffBuilder({prettyPrinter: prettyPrinter}),
expectedMsg = 'Expected $.x.foo = 1 to equal 2.\n' +
"Expected $.x.baz = undefined to equal 3.";
diffBuilder.setRoots(
{x: {foo: 1, bar: 2}},
{x: jasmine.objectContaining({foo: 2, baz: 3})}
);
diffBuilder.withPath('x', function() {
diffBuilder.withPath('foo', function () {
diffBuilder.recordMismatch();
});
diffBuilder.withPath('baz', function () {
diffBuilder.recordMismatch();
});
});
expect(diffBuilder.getMessage()).toEqual(expectedMsg);
});
});
@@ -0,0 +1,52 @@
/* eslint-disable compat/compat */
describe('toBePending', function() {
it('passes if the actual promise is pending', function() {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
matcher = jasmineUnderTest.asyncMatchers.toBePending(matchersUtil),
actual = new Promise(function() {});
return matcher.compare(actual).then(function(result) {
expect(result).toEqual(jasmine.objectContaining({pass: true}));
});
});
it('fails if the actual promise is resolved', function() {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
matcher = jasmineUnderTest.asyncMatchers.toBePending(matchersUtil),
actual = Promise.resolve();
return matcher.compare(actual).then(function(result) {
expect(result).toEqual(jasmine.objectContaining({pass: false}));
});
});
it('fails if the actual promise is rejected', function() {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
matcher = jasmineUnderTest.asyncMatchers.toBePending(matchersUtil),
actual = Promise.reject(new Error('promise was rejected'));
return matcher.compare(actual).then(function(result) {
expect(result).toEqual(jasmine.objectContaining({pass: false}));
});
});
it('fails if actual is not a promise', function() {
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
matcher = jasmineUnderTest.asyncMatchers.toBePending(matchersUtil),
actual = 'not a promise';
function f() {
return matcher.compare(actual);
}
expect(f).toThrowError(
'Expected toBePending to be called on a promise.'
);
});
});
@@ -1,3 +1,4 @@
/* eslint-disable compat/compat */
describe('toBeRejected', function() {
it('passes if the actual is rejected', function() {
jasmine.getEnv().requirePromises();
@@ -1,8 +1,9 @@
/* eslint-disable compat/compat */
describe('#toBeRejectedWithError', function () {
it('passes when Error type matches', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new TypeError('foo'));
@@ -17,7 +18,7 @@ describe('#toBeRejectedWithError', function () {
it('passes when Error type and message matches', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new TypeError('foo'));
@@ -32,7 +33,7 @@ describe('#toBeRejectedWithError', function () {
it('passes when Error matches and is exactly Error', function() {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error());
@@ -48,7 +49,7 @@ describe('#toBeRejectedWithError', function () {
it('passes when Error message matches a string', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error('foo'));
@@ -63,7 +64,7 @@ describe('#toBeRejectedWithError', function () {
it('passes when Error message matches a RegExp', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error('foo'));
@@ -78,7 +79,7 @@ describe('#toBeRejectedWithError', function () {
it('passes when Error message is empty', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error());
@@ -93,7 +94,7 @@ describe('#toBeRejectedWithError', function () {
it('passes when no arguments', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error());
@@ -108,7 +109,7 @@ describe('#toBeRejectedWithError', function () {
it('fails when resolved', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.resolve(new Error('foo'));
@@ -123,7 +124,7 @@ describe('#toBeRejectedWithError', function () {
it('fails when rejected with non Error type', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject('foo');
@@ -138,7 +139,7 @@ describe('#toBeRejectedWithError', function () {
it('fails when Error type mismatches', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error('foo'));
@@ -153,7 +154,7 @@ describe('#toBeRejectedWithError', function () {
it('fails when Error message mismatches', function () {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = Promise.reject(new Error('foo'));
@@ -166,7 +167,7 @@ describe('#toBeRejectedWithError', function () {
});
it('fails if actual is not a promise', function() {
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeRejectedWithError(matchersUtil),
actual = 'not a promise';
@@ -1,3 +1,4 @@
/* eslint-disable compat/compat */
describe('#toBeRejectedWith', function () {
it('should return true if the promise is rejected with the expected value', function () {
jasmine.getEnv().requirePromises();
@@ -1,3 +1,4 @@
/* eslint-disable compat/compat */
describe('toBeResolved', function() {
it('passes if the actual is resolved', function() {
jasmine.getEnv().requirePromises();
@@ -1,3 +1,4 @@
/* eslint-disable compat/compat */
describe('#toBeResolvedTo', function() {
it('passes if the promise is resolved to the expected value', function() {
jasmine.getEnv().requirePromises();
@@ -14,7 +15,7 @@ describe('#toBeResolvedTo', function() {
it('fails if the promise is rejected', function() {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
actual = Promise.reject('AsyncExpectationSpec error');
@@ -29,7 +30,7 @@ describe('#toBeResolvedTo', function() {
it('fails if the promise is resolved to a different value', function() {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
actual = Promise.resolve({foo: 17});
@@ -44,7 +45,7 @@ describe('#toBeResolvedTo', function() {
it('builds its message correctly when negated', function() {
jasmine.getEnv().requirePromises();
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: new jasmineUnderTest.makePrettyPrinter()}),
var matchersUtil = new jasmineUnderTest.MatchersUtil({pp: jasmineUnderTest.makePrettyPrinter()}),
matcher = jasmineUnderTest.asyncMatchers.toBeResolvedTo(matchersUtil),
actual = Promise.resolve(true);
+41 -37
View File
@@ -112,6 +112,11 @@ describe("matchersUtil", function() {
expect(matchersUtil.equals(123, 456)).toBe(false);
});
it("fails for a Number and a String that have equivalent values", function() {
var matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(matchersUtil.equals(123, "123")).toBe(false);
});
it("passes for Dates that are equivalent", function() {
var matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(matchersUtil.equals(new Date("Jan 1, 1970"), new Date("Jan 1, 1970"))).toBe(true);
@@ -280,8 +285,8 @@ describe("matchersUtil", function() {
it("passes for equivalent Promises (GitHub issue #1314)", function() {
if (typeof Promise === 'undefined') { return; }
var p1 = new Promise(function () {}),
p2 = new Promise(function () {}),
var p1 = new Promise(function () {}), // eslint-disable-line compat/compat
p2 = new Promise(function () {}), // eslint-disable-line compat/compat
matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(matchersUtil.equals(p1, p1)).toBe(true);
@@ -416,10 +421,10 @@ describe("matchersUtil", function() {
jasmine.getEnv().requireFunctioningMaps();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var obj = new Map();
var obj = new Map(); // eslint-disable-line compat/compat
obj.set(1, 2);
obj.set('foo', 'bar');
var containing = new jasmineUnderTest.MapContaining(new Map());
var containing = new jasmineUnderTest.MapContaining(new Map()); // eslint-disable-line compat/compat
containing.sample.set('foo', 'bar');
expect(matchersUtil.equals(obj, containing)).toBe(true);
@@ -430,10 +435,10 @@ describe("matchersUtil", function() {
jasmine.getEnv().requireFunctioningSets();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var obj = new Set();
var obj = new Set(); // eslint-disable-line compat/compat
obj.add(1);
obj.add('foo');
var containing = new jasmineUnderTest.SetContaining(new Set());
var containing = new jasmineUnderTest.SetContaining(new Set()); // eslint-disable-line compat/compat
containing.sample.add(1);
expect(matchersUtil.equals(obj, containing)).toBe(true);
@@ -610,17 +615,17 @@ describe("matchersUtil", function() {
it("passes when comparing two empty sets", function() {
jasmine.getEnv().requireFunctioningSets();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(matchersUtil.equals(new Set(), new Set())).toBe(true);
expect(matchersUtil.equals(new Set(), new Set())).toBe(true); // eslint-disable-line compat/compat
});
it("passes when comparing identical sets", function() {
jasmine.getEnv().requireFunctioningSets();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var setA = new Set();
var setA = new Set(); // eslint-disable-line compat/compat
setA.add(6);
setA.add(5);
var setB = new Set();
var setB = new Set(); // eslint-disable-line compat/compat
setB.add(6);
setB.add(5);
@@ -631,10 +636,10 @@ describe("matchersUtil", function() {
jasmine.getEnv().requireFunctioningSets();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var setA = new Set();
var setA = new Set(); // eslint-disable-line compat/compat
setA.add(3);
setA.add(6);
var setB = new Set();
var setB = new Set(); // eslint-disable-line compat/compat
setB.add(6);
setB.add(3);
@@ -645,24 +650,23 @@ describe("matchersUtil", function() {
jasmine.getEnv().requireFunctioningSets();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var setA1 = new Set();
var setA1 = new Set(); // eslint-disable-line compat/compat
setA1.add(['a',3]);
setA1.add([6,1]);
var setA2 = new Set();
var setA2 = new Set(); // eslint-disable-line compat/compat
setA1.add(['y',3]);
setA1.add([6,1]);
var setA = new Set();
var setA = new Set(); // eslint-disable-line compat/compat
setA.add(setA1);
setA.add(setA2);
var setB1 = new Set();
var setB1 = new Set(); // eslint-disable-line compat/compat
setB1.add([6,1]);
setB1.add(['a',3]);
var setB2 = new Set();
var setB2 = new Set(); // eslint-disable-line compat/compat
setB1.add([6,1]);
setB1.add(['y',3]);
var setB = new Set();
var setB = new Set(); // eslint-disable-line compat/compat
setB.add(setB1);
setB.add(setB2);
@@ -673,10 +677,10 @@ describe("matchersUtil", function() {
jasmine.getEnv().requireFunctioningSets();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var setA = new Set();
var setA = new Set(); // eslint-disable-line compat/compat
setA.add([[1,2], [3,4]]);
setA.add([[5,6], [7,8]]);
var setB = new Set();
var setB = new Set(); // eslint-disable-line compat/compat
setB.add([[5,6], [7,8]]);
setB.add([[1,2], [3,4]]);
@@ -686,11 +690,11 @@ describe("matchersUtil", function() {
it("fails for sets with different elements", function() {
jasmine.getEnv().requireFunctioningSets();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var setA = new Set();
var setA = new Set(); // eslint-disable-line compat/compat
setA.add(6);
setA.add(3);
setA.add(5);
var setB = new Set();
var setB = new Set(); // eslint-disable-line compat/compat
setB.add(6);
setB.add(4);
setB.add(5);
@@ -701,10 +705,10 @@ describe("matchersUtil", function() {
it("fails for sets of different size", function() {
jasmine.getEnv().requireFunctioningSets();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var setA = new Set();
var setA = new Set(); // eslint-disable-line compat/compat
setA.add(6);
setA.add(3);
var setB = new Set();
var setB = new Set(); // eslint-disable-line compat/compat
setB.add(6);
setB.add(4);
setB.add(5);
@@ -715,15 +719,15 @@ describe("matchersUtil", function() {
it("passes when comparing two empty maps", function() {
jasmine.getEnv().requireFunctioningMaps();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(matchersUtil.equals(new Map(), new Map())).toBe(true);
expect(matchersUtil.equals(new Map(), new Map())).toBe(true); // eslint-disable-line compat/compat
});
it("passes when comparing identical maps", function() {
jasmine.getEnv().requireFunctioningMaps();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var mapA = new Map();
var mapA = new Map(); // eslint-disable-line compat/compat
mapA.set(6, 5);
var mapB = new Map();
var mapB = new Map(); // eslint-disable-line compat/compat
mapB.set(6, 5);
expect(matchersUtil.equals(mapA, mapB)).toBe(true);
});
@@ -731,10 +735,10 @@ describe("matchersUtil", function() {
it("passes when comparing identical maps with different insertion order", function() {
jasmine.getEnv().requireFunctioningMaps();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var mapA = new Map();
var mapA = new Map(); // eslint-disable-line compat/compat
mapA.set("a", 3);
mapA.set(6, 1);
var mapB = new Map();
var mapB = new Map(); // eslint-disable-line compat/compat
mapB.set(6, 1);
mapB.set("a", 3);
expect(matchersUtil.equals(mapA, mapB)).toBe(true);
@@ -743,10 +747,10 @@ describe("matchersUtil", function() {
it("fails for maps with different elements", function() {
jasmine.getEnv().requireFunctioningMaps();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var mapA = new Map();
var mapA = new Map(); // eslint-disable-line compat/compat
mapA.set(6, 3);
mapA.set(5, 1);
var mapB = new Map();
var mapB = new Map(); // eslint-disable-line compat/compat
mapB.set(6, 4);
mapB.set(5, 1);
@@ -756,9 +760,9 @@ describe("matchersUtil", function() {
it("fails for maps of different size", function() {
jasmine.getEnv().requireFunctioningMaps();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var mapA = new Map();
var mapA = new Map(); // eslint-disable-line compat/compat
mapA.set(6, 3);
var mapB = new Map();
var mapB = new Map(); // eslint-disable-line compat/compat
mapB.set(6, 4);
mapB.set(5, 1);
expect(matchersUtil.equals(mapA, mapB)).toBe(false);
@@ -829,7 +833,7 @@ describe("matchersUtil", function() {
expect(diffBuilder.setRoots).toHaveBeenCalledWith(actual, expected);
expect(diffBuilder.withPath).toHaveBeenCalledWith('x', jasmine.any(Function));
expect(diffBuilder.recordMismatch). toHaveBeenCalledWith();
expect(diffBuilder.recordMismatch).toHaveBeenCalledWith();
});
it("records both objects when the tester does not implement valuesForDiff", function() {
@@ -846,7 +850,7 @@ describe("matchersUtil", function() {
expect(diffBuilder.setRoots).toHaveBeenCalledWith(actual, expected);
expect(diffBuilder.withPath).toHaveBeenCalledWith('x', jasmine.any(Function));
expect(diffBuilder.recordMismatch). toHaveBeenCalledWith();
expect(diffBuilder.recordMismatch).toHaveBeenCalledWith();
});
});
@@ -981,7 +985,7 @@ describe("matchersUtil", function() {
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var setItem = {'foo': 'bar'};
var set = new Set();
var set = new Set(); // eslint-disable-line compat/compat
set.add(setItem);
expect(matchersUtil.contains(set, setItem)).toBe(true);
@@ -992,7 +996,7 @@ describe("matchersUtil", function() {
jasmine.getEnv().requireFunctioningSets();
var matchersUtil = new jasmineUnderTest.MatchersUtil();
var set = new Set();
var set = new Set(); // eslint-disable-line compat/compat
set.add({'foo': 'bar'});
expect(matchersUtil.contains(set, {'foo': 'bar'})).toBe(false);
+60 -47
View File
@@ -261,8 +261,8 @@ describe("toEqual", function() {
it("reports mismatches between arrays of different types", function() {
jasmine.getEnv().requireFunctioningTypedArrays();
var actual = new Uint32Array([1, 2, 3]),
expected = new Uint16Array([1, 2, 3]),
var actual = new Uint32Array([1, 2, 3]), // eslint-disable-line compat/compat
expected = new Uint16Array([1, 2, 3]), // eslint-disable-line compat/compat
message = "Expected Uint32Array [ 1, 2, 3 ] to equal Uint16Array [ 1, 2, 3 ].";
expect(compareEquals(actual, expected).message).toEqual(message);
@@ -429,17 +429,30 @@ describe("toEqual", function() {
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports mismatches involving objectContaining and an object", function() {
var actual = {x: {a: 1, b: 4, c: 3, extra: 'ignored'}};
var expected = {x: jasmineUnderTest.objectContaining({a: 1, b: 2, c: 3})};
expect(compareEquals(actual, expected).message).toEqual('Expected $.x.b = 4 to equal 2.');
it('reports mismatches between an object and objectContaining', function() {
var actual = {a: 1, b: 4, c: 3, extra: 'ignored'};
var expected = jasmineUnderTest.objectContaining({a: 1, b: 2, c: 3, d: 4});
expect(compareEquals(actual, expected).message)
.toEqual(
'Expected $.b = 4 to equal 2.\n' +
'Expected $.d = undefined to equal 4.'
);
});
it("reports mismatches between a non-object and objectContaining", function() {
var actual = {x: 1};
var expected = {x: jasmineUnderTest.objectContaining({a: 1})};
var actual = 1;
var expected = jasmineUnderTest.objectContaining({a: 1});
expect(compareEquals(actual, expected).message).toEqual(
"Expected $.x = 1 to equal '<jasmine.objectContaining(Object({ a: 1 }))>'."
"Expected 1 to equal '<jasmine.objectContaining(Object({ a: 1 }))>'."
);
});
it("reports mismatches involving a nested objectContaining", function() {
var actual = {x: {a: 1, b: 4, c: 3, extra: 'ignored'}};
var expected = {x: jasmineUnderTest.objectContaining({a: 1, b: 2, c: 3, d: 4})};
expect(compareEquals(actual, expected).message).toEqual(
'Expected $.x.b = 4 to equal 2.\n' +
'Expected $.x.d = undefined to equal 4.'
);
});
@@ -448,9 +461,9 @@ describe("toEqual", function() {
it("reports mismatches between Sets", function() {
jasmine.getEnv().requireFunctioningSets();
var actual = new Set();
var actual = new Set(); // eslint-disable-line compat/compat
actual.add(1);
var expected = new Set();
var expected = new Set(); // eslint-disable-line compat/compat
expected.add(2);
var message = 'Expected Set( 1 ) to equal Set( 2 ).';
@@ -460,9 +473,9 @@ describe("toEqual", function() {
it("reports deep mismatches within Sets", function() {
jasmine.getEnv().requireFunctioningSets();
var actual = new Set();
var actual = new Set(); // eslint-disable-line compat/compat
actual.add({x: 1});
var expected = new Set();
var expected = new Set(); // eslint-disable-line compat/compat
expected.add({x: 2});
var message = 'Expected Set( Object({ x: 1 }) ) to equal Set( Object({ x: 2 }) ).';
@@ -472,9 +485,9 @@ describe("toEqual", function() {
it("reports mismatches between Sets nested in objects", function() {
jasmine.getEnv().requireFunctioningSets();
var actualSet = new Set();
var actualSet = new Set(); // eslint-disable-line compat/compat
actualSet.add(1);
var expectedSet = new Set();
var expectedSet = new Set(); // eslint-disable-line compat/compat
expectedSet.add(2);
var actual = { sets: [actualSet] };
@@ -487,10 +500,10 @@ describe("toEqual", function() {
it("reports mismatches between Sets of different lengths", function() {
jasmine.getEnv().requireFunctioningSets();
var actual = new Set();
var actual = new Set(); // eslint-disable-line compat/compat
actual.add(1);
actual.add(2);
var expected = new Set();
var expected = new Set(); // eslint-disable-line compat/compat
expected.add(2);
var message = 'Expected Set( 1, 2 ) to equal Set( 2 ).';
@@ -501,10 +514,10 @@ describe("toEqual", function() {
jasmine.getEnv().requireFunctioningSets();
// Use 'duplicate' object in actual so sizes match
var actual = new Set();
var actual = new Set(); // eslint-disable-line compat/compat
actual.add({x: 1});
actual.add({x: 1});
var expected = new Set();
var expected = new Set(); // eslint-disable-line compat/compat
expected.add({x: 1});
expected.add({x: 2});
var message = 'Expected Set( Object({ x: 1 }), Object({ x: 1 }) ) to equal Set( Object({ x: 1 }), Object({ x: 2 }) ).';
@@ -516,10 +529,10 @@ describe("toEqual", function() {
jasmine.getEnv().requireFunctioningSets();
// Use 'duplicate' object in expected so sizes match
var actual = new Set();
var actual = new Set(); // eslint-disable-line compat/compat
actual.add({x: 1});
actual.add({x: 2});
var expected = new Set();
var expected = new Set(); // eslint-disable-line compat/compat
expected.add({x: 1});
expected.add({x: 1});
var message = 'Expected Set( Object({ x: 1 }), Object({ x: 2 }) ) to equal Set( Object({ x: 1 }), Object({ x: 1 }) ).';
@@ -533,9 +546,9 @@ describe("toEqual", function() {
jasmine.getEnv().requireFunctioningMaps();
// values are the same but with different object identity
var actual = new Map();
var actual = new Map(); // eslint-disable-line compat/compat
actual.set('a',{x:1});
var expected = new Map();
var expected = new Map(); // eslint-disable-line compat/compat
expected.set('a',{x:1});
expect(compareEquals(actual, expected).pass).toBe(true);
@@ -544,9 +557,9 @@ describe("toEqual", function() {
it("reports deep mismatches within Maps", function() {
jasmine.getEnv().requireFunctioningMaps();
var actual = new Map();
var actual = new Map(); // eslint-disable-line compat/compat
actual.set('a',{x:1});
var expected = new Map();
var expected = new Map(); // eslint-disable-line compat/compat
expected.set('a',{x:2});
var message = "Expected Map( [ 'a', Object({ x: 1 }) ] ) to equal Map( [ 'a', Object({ x: 2 }) ] ).";
@@ -556,9 +569,9 @@ describe("toEqual", function() {
it("reports mismatches between Maps nested in objects", function() {
jasmine.getEnv().requireFunctioningMaps();
var actual = {Maps:[new Map()]};
var actual = {Maps:[new Map()]}; // eslint-disable-line compat/compat
actual.Maps[0].set('a',1);
var expected = {Maps:[new Map()]};
var expected = {Maps:[new Map()]}; // eslint-disable-line compat/compat
expected.Maps[0].set('a',2);
var message = "Expected $.Maps[0] = Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ] ).";
@@ -569,9 +582,9 @@ describe("toEqual", function() {
it("reports mismatches between Maps of different lengths", function() {
jasmine.getEnv().requireFunctioningMaps();
var actual = new Map();
var actual = new Map(); // eslint-disable-line compat/compat
actual.set('a',1);
var expected = new Map();
var expected = new Map(); // eslint-disable-line compat/compat
expected.set('a',2);
expected.set('b',1);
var message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ], [ 'b', 1 ] ).";
@@ -582,9 +595,9 @@ describe("toEqual", function() {
it("reports mismatches between Maps with equal values but differing keys", function() {
jasmine.getEnv().requireFunctioningMaps();
var actual = new Map();
var actual = new Map(); // eslint-disable-line compat/compat
actual.set('a',1);
var expected = new Map();
var expected = new Map(); // eslint-disable-line compat/compat
expected.set('b',1);
var message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'b', 1 ] ).";
@@ -594,9 +607,9 @@ describe("toEqual", function() {
it("does not report mismatches between Maps with keys with same object identity", function() {
jasmine.getEnv().requireFunctioningMaps();
var key = {x: 1};
var actual = new Map();
var actual = new Map(); // eslint-disable-line compat/compat
actual.set(key,2);
var expected = new Map();
var expected = new Map(); // eslint-disable-line compat/compat
expected.set(key,2);
expect(compareEquals(actual, expected).pass).toBe(true);
@@ -605,9 +618,9 @@ describe("toEqual", function() {
it("reports mismatches between Maps with identical keys with different object identity", function() {
jasmine.getEnv().requireFunctioningMaps();
var actual = new Map();
var actual = new Map(); // eslint-disable-line compat/compat
actual.set({x:1},2);
var expected = new Map();
var expected = new Map(); // eslint-disable-line compat/compat
expected.set({x:1},2);
var message = "Expected Map( [ Object({ x: 1 }), 2 ] ) to equal Map( [ Object({ x: 1 }), 2 ] ).";
@@ -617,9 +630,9 @@ describe("toEqual", function() {
it("does not report mismatches when comparing Map key to jasmine.anything()", function() {
jasmine.getEnv().requireFunctioningMaps();
var actual = new Map();
var actual = new Map(); // eslint-disable-line compat/compat
actual.set('a',1);
var expected = new Map();
var expected = new Map(); // eslint-disable-line compat/compat
expected.set(jasmineUnderTest.anything(),1);
expect(compareEquals(actual, expected).pass).toBe(true);
@@ -629,10 +642,10 @@ describe("toEqual", function() {
jasmine.getEnv().requireFunctioningMaps();
jasmine.getEnv().requireFunctioningSymbols();
var key = Symbol();
var actual = new Map();
var key = Symbol(); // eslint-disable-line compat/compat
var actual = new Map(); // eslint-disable-line compat/compat
actual.set(key,1);
var expected = new Map();
var expected = new Map(); // eslint-disable-line compat/compat
expected.set(key,1);
expect(compareEquals(actual, expected).pass).toBe(true);
@@ -642,10 +655,10 @@ describe("toEqual", function() {
jasmine.getEnv().requireFunctioningMaps();
jasmine.getEnv().requireFunctioningSymbols();
var actual = new Map();
actual.set(Symbol(),1);
var expected = new Map();
expected.set(Symbol(),1);
var actual = new Map(); // eslint-disable-line compat/compat
actual.set(Symbol(),1); // eslint-disable-line compat/compat
var expected = new Map(); // eslint-disable-line compat/compat
expected.set(Symbol(),1); // eslint-disable-line compat/compat
var message = "Expected Map( [ Symbol(), 1 ] ) to equal Map( [ Symbol(), 1 ] ).";
expect(compareEquals(actual, expected).message).toBe(message);
@@ -655,9 +668,9 @@ describe("toEqual", function() {
jasmine.getEnv().requireFunctioningMaps();
jasmine.getEnv().requireFunctioningSymbols();
var actual = new Map();
actual.set(Symbol(),1);
var expected = new Map();
var actual = new Map(); // eslint-disable-line compat/compat
actual.set(Symbol(),1); // eslint-disable-line compat/compat
var expected = new Map(); // eslint-disable-line compat/compat
expected.set(jasmineUnderTest.anything(),1);
expect(compareEquals(actual, expected).pass).toBe(true);
@@ -0,0 +1,95 @@
describe("toHaveBeenCalledOnceWith", function () {
it("passes when the actual was called only once and with matching parameters", function () {
var pp = jasmineUnderTest.makePrettyPrinter(),
util = new jasmineUnderTest.MatchersUtil({ pp: pp }),
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
calledSpy = new jasmineUnderTest.Spy('called-spy'),
result;
calledSpy('a', 'b');
result = matcher.compare(calledSpy, 'a', 'b');
expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected spy called-spy to have been called 0 times, multiple times, or once, but with arguments different from:\n [ 'a', 'b' ]\nBut the actual call was:\n [ 'a', 'b' ].\n\n");
});
it("supports custom equality testers", function () {
var customEqualityTesters = [function() { return true; }],
matchersUtil = new jasmineUnderTest.MatchersUtil({customTesters: customEqualityTesters}),
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(matchersUtil),
calledSpy = new jasmineUnderTest.Spy('called-spy'),
result;
calledSpy('a', 'b');
result = matcher.compare(calledSpy, 'a', 'a');
expect(result.pass).toBe(true);
});
it("fails when the actual was never called", function () {
var pp = jasmineUnderTest.makePrettyPrinter(),
util = new jasmineUnderTest.MatchersUtil({ pp: pp }),
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
calledSpy = new jasmineUnderTest.Spy('called-spy'),
result;
result = matcher.compare(calledSpy, 'a', 'b');
expect(result.pass).toBe(false);
expect(result.message).toEqual("Expected spy called-spy to have been called only once, and with given args:\n [ 'a', 'b' ]\nBut it was never called.\n\n");
});
it("fails when the actual was called once with different parameters", function () {
var pp = jasmineUnderTest.makePrettyPrinter(),
util = new jasmineUnderTest.MatchersUtil({ pp: pp }),
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
calledSpy = new jasmineUnderTest.Spy('called-spy'),
result;
calledSpy('a', 'c');
result = matcher.compare(calledSpy, 'a', 'b');
expect(result.pass).toBe(false);
expect(result.message).toEqual("Expected spy called-spy to have been called only once, and with given args:\n [ 'a', 'b' ]\nBut the actual call was:\n [ 'a', 'c' ].\nExpected $[1] = 'c' to equal 'b'.\n\n");
});
it("fails when the actual was called multiple times with expected parameters", function () {
var pp = jasmineUnderTest.makePrettyPrinter(),
util = new jasmineUnderTest.MatchersUtil({ pp: pp }),
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
calledSpy = new jasmineUnderTest.Spy('called-spy'),
result;
calledSpy('a', 'b');
calledSpy('a', 'b');
result = matcher.compare(calledSpy, 'a', 'b');
expect(result.pass).toBe(false);
expect(result.message).toEqual("Expected spy called-spy to have been called only once, and with given args:\n [ 'a', 'b' ]\nBut the actual calls were:\n [ 'a', 'b' ],\n [ 'a', 'b' ].\n\n");
});
it("fails when the actual was called multiple times (one of them - with expected parameters)", function () {
var pp = jasmineUnderTest.makePrettyPrinter(),
util = new jasmineUnderTest.MatchersUtil({ pp: pp }),
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
calledSpy = new jasmineUnderTest.Spy('called-spy'),
result;
calledSpy('a', 'b');
calledSpy('a', 'c');
result = matcher.compare(calledSpy, 'a', 'b');
expect(result.pass).toBe(false);
expect(result.message).toEqual("Expected spy called-spy to have been called only once, and with given args:\n [ 'a', 'b' ]\nBut the actual calls were:\n [ 'a', 'b' ],\n [ 'a', 'c' ].\n\n");
});
it("throws an exception when the actual is not a spy", function () {
var pp = jasmineUnderTest.makePrettyPrinter(),
util = new jasmineUnderTest.MatchersUtil({ pp: pp }),
matcher = jasmineUnderTest.matchers.toHaveBeenCalledOnceWith(util),
fn = function () { };
expect(function () { matcher.compare(fn) }).toThrowError(/Expected a spy, but got Function./);
});
});
+138
View File
@@ -0,0 +1,138 @@
/* eslint-disable compat/compat */
describe('toHaveSize', function() {
'use strict';
it('passes for an array whose length matches', function() {
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare([1, 2], 2);
expect(result.pass).toBe(true);
});
it('fails for an array whose length does not match', function() {
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare([1, 2, 3], 2);
expect(result.pass).toBe(false);
});
it('passes for an object with the proper number of keys', function() {
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare({a: 1, b: 2}, 2);
expect(result.pass).toBe(true);
});
it('fails for an object with a different number of keys', function() {
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare({a: 1, b: 2}, 1);
expect(result.pass).toBe(false);
});
it('passes for an object with an explicit `length` property that matches', function() {
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare({a: 1, b: 2, length: 5}, 5);
expect(result.pass).toBe(true);
});
it('fails for an object with an explicit `length` property that does not match', function() {
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare({a: 1, b: 2, length: 5}, 1);
expect(result.pass).toBe(false);
});
it('passes for a string whose length matches', function() {
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare('ab', 2);
expect(result.pass).toBe(true);
});
it('fails for a string whose length does not match', function() {
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare('abc', 2);
expect(result.pass).toBe(false);
});
it('passes for a Map whose length matches', function() {
jasmine.getEnv().requireFunctioningMaps();
var map = new Map();
map.set('a',1);
map.set('b',2);
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare(map, 2);
expect(result.pass).toBe(true);
});
it('fails for a Map whose length does not match', function() {
jasmine.getEnv().requireFunctioningMaps();
var map = new Map();
map.set('a',1);
map.set('b',2);
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare(map, 1);
expect(result.pass).toBe(false);
});
it('passes for a Set whose length matches', function() {
jasmine.getEnv().requireFunctioningSets();
var set = new Set();
set.add('a');
set.add('b');
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare(set, 2);
expect(result.pass).toBe(true);
});
it('fails for a Set whose length does not match', function() {
jasmine.getEnv().requireFunctioningSets();
var set = new Set();
set.add('a');
set.add('b');
var matcher = jasmineUnderTest.matchers.toHaveSize(),
result = matcher.compare(set, 1);
expect(result.pass).toBe(false);
});
it('throws an error for WeakSet', function() {
jasmine.getEnv().requireWeakSets();
var matcher = jasmineUnderTest.matchers.toHaveSize();
expect(function() {
matcher.compare(new WeakSet(), 2);
}).toThrowError('Cannot get size of [object WeakSet].');
});
it('throws an error for WeakMap', function() {
jasmine.getEnv().requireWeakMaps();
var matcher = jasmineUnderTest.matchers.toHaveSize();
expect(function() {
matcher.compare(new WeakMap(), 2);
}).toThrowError(/Cannot get size of \[object (WeakMap|Object)\]\./);
});
it('throws an error for DataView', function() {
var matcher = jasmineUnderTest.matchers.toHaveSize();
expect(function() {
matcher.compare(new DataView(new ArrayBuffer(128)), 2);
}).toThrowError(/Cannot get size of \[object (DataView|Object)\]\./);
});
});