Merge common async/sync expectation stuff

This commit is contained in:
Gregg Van Hove
2018-10-24 16:17:30 -07:00
parent 1e47dcf2cc
commit 2d303a6e46
8 changed files with 441 additions and 522 deletions

View File

@@ -1,20 +1,20 @@
describe('AsyncExpectation', function() {
beforeEach(function() {
jasmineUnderTest.AsyncExpectation.addCoreMatchers(jasmineUnderTest.asyncMatchers);
jasmineUnderTest.Expectation.addAsyncCoreMatchers(jasmineUnderTest.asyncMatchers);
});
describe('Factory', function() {
it('throws an Error if promises are not available', function() {
var thenable = {then: function() {}},
options = {global: {}, actual: thenable}
function f() { jasmineUnderTest.AsyncExpectation.factory(options); }
function f() { jasmineUnderTest.Expectation.asyncFactory(options); }
expect(f).toThrowError('expectAsync is unavailable because the environment does not support promises.');
});
it('throws an Error if the argument is not a promise', function() {
jasmine.getEnv().requirePromises();
function f() {
jasmineUnderTest.AsyncExpectation.factory({actual: 'not a promise'});
jasmineUnderTest.Expectation.asyncFactory({actual: 'not a promise'});
}
expect(f).toThrowError('Expected expectAsync to be called with a promise.');
});
@@ -26,7 +26,7 @@ describe('AsyncExpectation', function() {
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
actual = Promise.resolve(),
expectation = jasmineUnderTest.AsyncExpectation.factory({
expectation = jasmineUnderTest.Expectation.asyncFactory({
util: jasmineUnderTest.matchersUtil,
actual: actual,
addExpectationResult: addExpectationResult
@@ -47,7 +47,7 @@ describe('AsyncExpectation', function() {
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
actual = Promise.reject(),
expectation = jasmineUnderTest.AsyncExpectation.factory({
expectation = jasmineUnderTest.Expectation.asyncFactory({
util: jasmineUnderTest.matchersUtil,
actual: actual,
addExpectationResult: addExpectationResult
@@ -66,18 +66,19 @@ describe('AsyncExpectation', function() {
it('propagates rejections from the comparison function', function() {
jasmine.getEnv().requirePromises();
var error = new Error('AsyncExpectationSpec failure');
var error = new Error('ExpectationSpec failure');
spyOn(jasmineUnderTest.AsyncExpectation.prototype, 'toBeResolved')
.and.returnValue(Promise.reject(error));
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
actual = dummyPromise(),
expectation = new jasmineUnderTest.AsyncExpectation({
expectation = jasmineUnderTest.Expectation.asyncFactory({
actual: actual,
addExpectationResult: addExpectationResult
});
spyOn(expectation, 'toBeResolved')
.and.returnValue(Promise.reject(error));
return expectation.toBeResolved()
.then(
function() { fail('Expected a rejection'); },
@@ -93,7 +94,7 @@ describe('AsyncExpectation', function() {
buildFailureMessage: function() { return 'failure message'; }
},
addExpectationResult = jasmine.createSpy('addExpectationResult'),
expectation = jasmineUnderTest.AsyncExpectation.factory({
expectation = jasmineUnderTest.Expectation.asyncFactory({
actual: Promise.reject('rejected'),
addExpectationResult: addExpectationResult,
util: util
@@ -116,7 +117,7 @@ describe('AsyncExpectation', function() {
buildFailureMessage: function() { return 'failure message'; }
},
addExpectationResult = jasmine.createSpy('addExpectationResult'),
expectation = jasmineUnderTest.AsyncExpectation.factory({
expectation = jasmineUnderTest.Expectation.asyncFactory({
actual: Promise.reject('b'),
addExpectationResult: addExpectationResult,
util: util
@@ -141,7 +142,7 @@ describe('AsyncExpectation', function() {
},
addExpectationResult = jasmine.createSpy('addExpectationResult'),
actual = Promise.reject(),
expectation = jasmineUnderTest.AsyncExpectation.factory({
expectation = jasmineUnderTest.Expectation.asyncFactory({
actual: actual,
addExpectationResult: addExpectationResult,
util: util
@@ -162,7 +163,7 @@ describe('AsyncExpectation', function() {
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
actual = Promise.resolve(),
expectation = jasmineUnderTest.AsyncExpectation.factory({
expectation = jasmineUnderTest.Expectation.asyncFactory({
actual: actual,
addExpectationResult: addExpectationResult,
util: jasmineUnderTest.matchersUtil
@@ -183,7 +184,7 @@ describe('AsyncExpectation', function() {
var addExpectationResult = jasmine.createSpy('addExpectationResult'),
actual = Promise.resolve('a'),
expectation = jasmineUnderTest.AsyncExpectation.factory({
expectation = jasmineUnderTest.Expectation.asyncFactory({
actual: actual,
addExpectationResult: addExpectationResult,
util: jasmineUnderTest.matchersUtil

View File

@@ -6,7 +6,7 @@ describe("Expectation", function() {
},
expectation;
expectation = new jasmineUnderTest.Expectation({
expectation = jasmineUnderTest.Expectation.factory({
customMatchers: matchers
});
@@ -22,7 +22,7 @@ describe("Expectation", function() {
jasmineUnderTest.Expectation.addCoreMatchers(coreMatchers);
expectation = new jasmineUnderTest.Expectation({});
expectation = jasmineUnderTest.Expectation.factory({});
expect(expectation.toQuux).toBeDefined();
});
@@ -40,7 +40,7 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
expectation = new jasmineUnderTest.Expectation({
expectation = jasmineUnderTest.Expectation.factory({
util: util,
customMatchers: matchers,
customEqualityTesters: customEqualityTesters,
@@ -68,7 +68,7 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
expectation = new jasmineUnderTest.Expectation({
expectation = jasmineUnderTest.Expectation.factory({
util: util,
customMatchers: matchers,
actual: "an actual",
@@ -94,7 +94,7 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
expectation = new jasmineUnderTest.Expectation({
expectation = jasmineUnderTest.Expectation.factory({
customMatchers: matchers,
util: util,
actual: "an actual",
@@ -109,7 +109,8 @@ describe("Expectation", function() {
message: "",
error: undefined,
expected: "hello",
actual: "an actual"
actual: "an actual",
errorForStack: undefined
});
});
@@ -127,7 +128,7 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
expectation = new jasmineUnderTest.Expectation({
expectation = jasmineUnderTest.Expectation.factory({
customMatchers: matchers,
util: util,
actual: "an actual",
@@ -142,7 +143,8 @@ describe("Expectation", function() {
expected: "hello",
actual: "an actual",
message: "",
error: undefined
error: undefined,
errorForStack: undefined
});
});
@@ -162,7 +164,7 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
expectation = new jasmineUnderTest.Expectation({
expectation = jasmineUnderTest.Expectation.factory({
actual: "an actual",
customMatchers: matchers,
addExpectationResult: addExpectationResult
@@ -176,7 +178,8 @@ describe("Expectation", function() {
expected: "hello",
actual: "an actual",
message: "I am a custom message",
error: undefined
error: undefined,
errorForStack: undefined
});
});
@@ -196,7 +199,7 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
expectation = new jasmineUnderTest.Expectation({
expectation = jasmineUnderTest.Expectation.factory({
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult
@@ -210,7 +213,8 @@ describe("Expectation", function() {
expected: "hello",
actual: "an actual",
message: "I am a custom message",
error: undefined
error: undefined,
errorForStack: undefined
});
});
@@ -229,7 +233,7 @@ describe("Expectation", function() {
actual = "an actual",
expectation;
expectation = jasmineUnderTest.Expectation.Factory({
expectation = jasmineUnderTest.Expectation.factory({
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult
@@ -243,7 +247,8 @@ describe("Expectation", function() {
message: "",
error: undefined,
expected: "hello",
actual: actual
actual: actual,
errorForStack: undefined
});
});
@@ -262,7 +267,7 @@ describe("Expectation", function() {
actual = "an actual",
expectation;
expectation = jasmineUnderTest.Expectation.Factory({
expectation = jasmineUnderTest.Expectation.factory({
customMatchers: matchers,
actual: "an actual",
util: util,
@@ -277,7 +282,8 @@ describe("Expectation", function() {
expected: "hello",
actual: actual,
message: "default message",
error: undefined
error: undefined,
errorForStack: undefined
});
});
@@ -298,7 +304,7 @@ describe("Expectation", function() {
actual = "an actual",
expectation;
expectation = jasmineUnderTest.Expectation.Factory({
expectation = jasmineUnderTest.Expectation.factory({
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult
@@ -312,7 +318,8 @@ describe("Expectation", function() {
expected: "hello",
actual: actual,
message: "I am a custom message",
error: undefined
error: undefined,
errorForStack: undefined
});
});
@@ -329,7 +336,7 @@ describe("Expectation", function() {
actual = "an actual",
expectation;
expectation = jasmineUnderTest.Expectation.Factory({
expectation = jasmineUnderTest.Expectation.factory({
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult
@@ -343,7 +350,8 @@ describe("Expectation", function() {
expected: "hello",
actual: actual,
message: "",
error: undefined
error: undefined,
errorForStack: undefined
});
});
@@ -365,7 +373,7 @@ describe("Expectation", function() {
actual = "an actual",
expectation;
expectation = jasmineUnderTest.Expectation.Factory({
expectation = jasmineUnderTest.Expectation.factory({
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult,
@@ -379,7 +387,8 @@ describe("Expectation", function() {
expected: "hello",
actual: actual,
message: "I'm a custom message",
error: undefined
error: undefined,
errorForStack: undefined
});
});
@@ -401,7 +410,7 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
expectation = new jasmineUnderTest.Expectation({
expectation = jasmineUnderTest.Expectation.factory({
actual: "an actual",
customMatchers: matchers,
addExpectationResult: addExpectationResult
@@ -415,7 +424,8 @@ describe("Expectation", function() {
expected: "hello",
actual: "an actual",
message: "I am a custom message",
error: customError
error: customError,
errorForStack: undefined
});
});
@@ -437,7 +447,7 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
expectation = jasmineUnderTest.Expectation.Factory({
expectation = jasmineUnderTest.Expectation.factory({
actual: "an actual",
customMatchers: matchers,
addExpectationResult: addExpectationResult
@@ -451,7 +461,8 @@ describe("Expectation", function() {
expected: "hello",
actual: "an actual",
message: "I am a custom message",
error: customError
error: customError,
errorForStack: undefined
});
});
@@ -473,7 +484,7 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
expectation = jasmineUnderTest.Expectation.Factory({
expectation = jasmineUnderTest.Expectation.factory({
actual: "an actual",
customMatchers: matchers,
addExpectationResult: addExpectationResult
@@ -487,7 +498,8 @@ describe("Expectation", function() {
expected: "hello",
actual: "an actual",
message: "I am a custom message",
error: customError
error: customError,
errorForStack: undefined
});
});
@@ -504,7 +516,7 @@ describe("Expectation", function() {
buildFailureMessage: function() { return "failure message"; }
},
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation = jasmineUnderTest.Expectation.Factory({
expectation = jasmineUnderTest.Expectation.factory({
customMatchers: matchers,
util: util,
actual: "an actual",
@@ -529,7 +541,7 @@ describe("Expectation", function() {
}
},
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation = jasmineUnderTest.Expectation.Factory({
expectation = jasmineUnderTest.Expectation.factory({
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult
@@ -558,7 +570,7 @@ describe("Expectation", function() {
}
},
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation = jasmineUnderTest.Expectation.Factory({
expectation = jasmineUnderTest.Expectation.factory({
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult
@@ -582,7 +594,7 @@ describe("Expectation", function() {
}
},
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation = jasmineUnderTest.Expectation.Factory({
expectation = jasmineUnderTest.Expectation.factory({
customMatchers: matchers,
util: jasmineUnderTest.matchersUtil,
actual: "an actual",
@@ -614,7 +626,7 @@ describe("Expectation", function() {
}
},
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation = jasmineUnderTest.Expectation.Factory({
expectation = jasmineUnderTest.Expectation.factory({
actual: "an actual",
customMatchers: matchers,
addExpectationResult: addExpectationResult