Added a basic set of async matchers

- Fixes #1447
- Fixes #1547
This commit is contained in:
Steve Gravrock
2018-06-04 21:01:22 -07:00
parent 8f7327cb4d
commit 9472df0db4
16 changed files with 876 additions and 34 deletions

View File

@@ -2415,4 +2415,106 @@ describe("Env integration", function() {
env.execute();
});
it('supports async matchers', function(done) {
jasmine.getEnv().requirePromises();
var env = new jasmineUnderTest.Env(),
specDone = jasmine.createSpy('specDone'),
suiteDone = jasmine.createSpy('suiteDone');
env.addReporter({
specDone: specDone,
suiteDone: suiteDone,
jasmineDone: function(result) {
expect(result.failedExpectations).toEqual([jasmine.objectContaining({
message: 'Expected a promise to be rejected.'
})]);
expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
description: 'has an async failure',
failedExpectations: [jasmine.objectContaining({
message: 'Expected a promise to be rejected.'
})]
}));
expect(suiteDone).toHaveBeenCalledWith(jasmine.objectContaining({
description: 'a suite',
failedExpectations: [jasmine.objectContaining({
message: 'Expected a promise to be rejected.'
})]
}));
done();
}
});
function fail(innerDone) {
var resolve;
var p = new Promise(function(res, rej) { resolve = res });
env.expectAsync(p).toBeRejected().then(innerDone);
resolve();
}
env.afterAll(fail);
env.describe('a suite', function() {
env.afterAll(fail);
env.it('has an async failure', fail);
});
env.execute();
});
it('provides custom equality testers to async matchers', function(done) {
jasmine.getEnv().requirePromises();
var env = new jasmineUnderTest.Env(),
specDone = jasmine.createSpy('specDone');
env.addReporter({
specDone: specDone,
jasmineDone: function() {
expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
description: 'has an async failure',
failedExpectations: []
}));
done();
}
});
env.it('has an async failure', function() {
env.addCustomEqualityTester(function() { return true; });
var p = Promise.resolve('something');
return env.expectAsync(p).toBeResolvedTo('something else');
});
env.execute();
});
it('includes useful stack frames in async matcher failures', function(done) {
jasmine.getEnv().requirePromises();
var env = new jasmineUnderTest.Env(),
specDone = jasmine.createSpy('specDone');
env.addReporter({
specDone: specDone,
jasmineDone: function() {
expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
failedExpectations: [jasmine.objectContaining({
stack: jasmine.stringMatching('EnvSpec.js')
})]
}));
done();
}
});
env.it('has an async failure', function() {
env.addCustomEqualityTester(function() { return true; });
var p = Promise.resolve();
return env.expectAsync(p).toBeRejected();
});
env.execute();
});
});