Converted some integration specs to async/await

This commit is contained in:
Steve Gravrock
2022-05-14 12:05:53 -07:00
parent 774c83a36e
commit c24b2f5a73
5 changed files with 450 additions and 464 deletions

View File

@@ -1,12 +1,18 @@
describe('Asymmetric equality testers (Integration)', function() { describe('Asymmetric equality testers (Integration)', function() {
function verifyPasses(expectations) { function verifyPasses(expectations) {
it('passes', function(done) { it('passes', async function() {
const env = new jasmineUnderTest.Env(); const env = new jasmineUnderTest.Env();
env.it('a spec', function() { env.it('a spec', function() {
expectations(env); expectations(env);
}); });
const specExpectations = function(result) { const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter);
await env.execute();
expect(reporter.specDone).toHaveBeenCalledTimes(1);
const result = reporter.specDone.calls.argsFor(0)[0];
expect(result.status).toEqual('passed'); expect(result.status).toEqual('passed');
expect(result.passedExpectations.length) expect(result.passedExpectations.length)
.withContext('Number of passed expectations') .withContext('Number of passed expectations')
@@ -19,37 +25,33 @@ describe('Asymmetric equality testers (Integration)', function() {
) )
.withContext('Failure message') .withContext('Failure message')
.toBeUndefined(); .toBeUndefined();
};
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
}); });
} }
function verifyFails(expectations) { function verifyFails(expectations) {
it('fails', function(done) { it('fails', async function() {
const env = new jasmineUnderTest.Env(); const env = new jasmineUnderTest.Env();
env.it('a spec', function() { env.it('a spec', function() {
expectations(env); expectations(env);
}); });
const specExpectations = function(result) { const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter);
await env.execute();
expect(reporter.specDone).toHaveBeenCalledTimes(1);
const result = reporter.specDone.calls.argsFor(0)[0];
expect(result.status).toEqual('failed'); expect(result.status).toEqual('failed');
expect(result.failedExpectations.length) expect(result.failedExpectations.length)
.withContext('Number of failed expectations') .withContext('Number of failed expectations')
.toEqual(1); .toEqual(1);
expect(result.failedExpectations[0].message) expect(result.failedExpectations[0].message)
.withContext( .withContext('Failed with a thrown error rather than a matcher failure')
'Failed with a thrown error rather than a matcher failure'
)
.not.toMatch(/^Error: /); .not.toMatch(/^Error: /);
expect(result.failedExpectations[0].matcherName) expect(result.failedExpectations[0].matcherName)
.withContext('Matcher name') .withContext('Matcher name')
.not.toEqual(''); .not.toEqual('');
};
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
}); });
} }

View File

@@ -10,7 +10,7 @@ describe('Custom Matchers (Integration)', function() {
env.cleanup_(); env.cleanup_();
}); });
it('allows adding more matchers local to a spec', function(done) { it('allows adding more matchers local to a spec', async function() {
env.it('spec defining a custom matcher', function() { env.it('spec defining a custom matcher', function() {
env.addMatchers({ env.addMatchers({
matcherForSpec: function() { matcherForSpec: function() {
@@ -37,20 +37,18 @@ describe('Custom Matchers (Integration)', function() {
}); });
const specDoneSpy = jasmine.createSpy('specDoneSpy'); const specDoneSpy = jasmine.createSpy('specDoneSpy');
const expectations = function() { env.addReporter({ specDone: specDoneSpy });
await env.execute();
const firstSpecResult = specDoneSpy.calls.first().args[0]; const firstSpecResult = specDoneSpy.calls.first().args[0];
expect(firstSpecResult.status).toEqual('failed'); expect(firstSpecResult.status).toEqual('failed');
expect(firstSpecResult.failedExpectations[0].message).toEqual( expect(firstSpecResult.failedExpectations[0].message).toEqual(
'matcherForSpec: actual: zzz; expected: yyy' 'matcherForSpec: actual: zzz; expected: yyy'
); );
done();
};
env.addReporter({ specDone: specDoneSpy });
env.execute(null, expectations);
}); });
it('passes the spec if the custom matcher passes', function(done) { it('passes the spec if the custom matcher passes', async function() {
env.it('spec using custom matcher', function() { env.it('spec using custom matcher', function() {
env.addMatchers({ env.addMatchers({
toBeReal: function() { toBeReal: function() {
@@ -65,15 +63,16 @@ describe('Custom Matchers (Integration)', function() {
env.expect(true).toBeReal(); env.expect(true).toBeReal();
}); });
const specExpectations = function(result) { const reporter = jasmine.createSpyObj('reporter', ['specDone']);
expect(result.status).toEqual('passed'); env.addReporter(reporter);
}; await env.execute();
env.addReporter({ specDone: specExpectations }); expect(reporter.specDone).toHaveBeenCalledTimes(1);
env.execute(null, done); const result = reporter.specDone.calls.argsFor(0)[0];
expect(result.status).toEqual('passed');
}); });
it('passes the spec if the custom equality matcher passes for types nested inside asymmetric equality testers', function(done) { it('passes the spec if the custom equality matcher passes for types nested inside asymmetric equality testers', async function() {
env.it('spec using custom equality matcher', function() { env.it('spec using custom equality matcher', function() {
const customEqualityFn = function(a, b) { const customEqualityFn = function(a, b) {
// All "foo*" strings match each other. // All "foo*" strings match each other.
@@ -99,15 +98,16 @@ describe('Custom Matchers (Integration)', function() {
.toEqual(jasmineUnderTest.arrayWithExactContents(['fooBar'])); .toEqual(jasmineUnderTest.arrayWithExactContents(['fooBar']));
}); });
const specExpectations = function(result) { const reporter = jasmine.createSpyObj('reporter', ['specDone']);
expect(result.status).toEqual('passed'); env.addReporter(reporter);
}; await env.execute();
env.addReporter({ specDone: specExpectations }); expect(reporter.specDone).toHaveBeenCalledTimes(1);
env.execute(null, done); const result = reporter.specDone.calls.argsFor(0)[0];
expect(result.status).toEqual('passed');
}); });
it('displays an appropriate failure message if a custom equality matcher fails', function(done) { it('displays an appropriate failure message if a custom equality matcher fails', async function() {
env.it('spec using custom equality matcher', function() { env.it('spec using custom equality matcher', function() {
const customEqualityFn = function(a, b) { const customEqualityFn = function(a, b) {
// "foo" is not equal to anything // "foo" is not equal to anything
@@ -120,18 +120,19 @@ describe('Custom Matchers (Integration)', function() {
env.expect({ foo: 'foo' }).toEqual({ foo: 'foo' }); env.expect({ foo: 'foo' }).toEqual({ foo: 'foo' });
}); });
const specExpectations = function(result) { const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter);
await env.execute();
expect(reporter.specDone).toHaveBeenCalledTimes(1);
const result = reporter.specDone.calls.argsFor(0)[0];
expect(result.status).toEqual('failed'); expect(result.status).toEqual('failed');
expect(result.failedExpectations[0].message).toEqual( expect(result.failedExpectations[0].message).toEqual(
"Expected $.foo = 'foo' to equal 'foo'." "Expected $.foo = 'foo' to equal 'foo'."
); );
};
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
}); });
it('uses the negative compare function for a negative comparison, if provided', function(done) { it('uses the negative compare function for a negative comparison, if provided', async function() {
env.it('spec with custom negative comparison matcher', function() { env.it('spec with custom negative comparison matcher', function() {
env.addMatchers({ env.addMatchers({
toBeReal: function() { toBeReal: function() {
@@ -149,15 +150,16 @@ describe('Custom Matchers (Integration)', function() {
env.expect(true).not.toBeReal(); env.expect(true).not.toBeReal();
}); });
const specExpectations = function(result) { const reporter = jasmine.createSpyObj('reporter', ['specDone']);
expect(result.status).toEqual('passed'); env.addReporter(reporter);
}; await env.execute();
env.addReporter({ specDone: specExpectations }); expect(reporter.specDone).toHaveBeenCalledTimes(1);
env.execute(null, done); const result = reporter.specDone.calls.argsFor(0)[0];
expect(result.status).toEqual('passed');
}); });
it('generates messages with the same rules as built in matchers absent a custom message', function(done) { it('generates messages with the same rules as built in matchers absent a custom message', async function() {
env.it('spec with an expectation', function() { env.it('spec with an expectation', function() {
env.addMatchers({ env.addMatchers({
toBeReal: function() { toBeReal: function() {
@@ -172,17 +174,18 @@ describe('Custom Matchers (Integration)', function() {
env.expect('a').toBeReal(); env.expect('a').toBeReal();
}); });
const specExpectations = function(result) { const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter);
await env.execute();
expect(reporter.specDone).toHaveBeenCalledTimes(1);
const result = reporter.specDone.calls.argsFor(0)[0];
expect(result.failedExpectations[0].message).toEqual( expect(result.failedExpectations[0].message).toEqual(
"Expected 'a' to be real." "Expected 'a' to be real."
); );
};
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
}); });
it('passes the expected and actual arguments to the comparison function', function(done) { it('passes the expected and actual arguments to the comparison function', async function() {
const argumentSpy = jasmine const argumentSpy = jasmine
.createSpy('argument spy') .createSpy('argument spy')
.and.returnValue({ pass: true }); .and.returnValue({ pass: true });
@@ -199,17 +202,13 @@ describe('Custom Matchers (Integration)', function() {
env.expect(true).toBeReal('arg1', 'arg2'); env.expect(true).toBeReal('arg1', 'arg2');
}); });
const specExpectations = function() { await env.execute();
expect(argumentSpy).toHaveBeenCalledWith(true); expect(argumentSpy).toHaveBeenCalledWith(true);
expect(argumentSpy).toHaveBeenCalledWith(true, 'arg'); expect(argumentSpy).toHaveBeenCalledWith(true, 'arg');
expect(argumentSpy).toHaveBeenCalledWith(true, 'arg1', 'arg2'); expect(argumentSpy).toHaveBeenCalledWith(true, 'arg1', 'arg2');
};
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
}); });
it('passes the jasmine utility to the matcher factory', function(done) { it('passes the jasmine utility to the matcher factory', async function() {
const matcherFactory = function() { const matcherFactory = function() {
return { return {
compare: function() { compare: function() {
@@ -229,17 +228,13 @@ describe('Custom Matchers (Integration)', function() {
env.expect(true).toBeReal(); env.expect(true).toBeReal();
}); });
const specExpectations = function() { await env.execute();
expect(matcherFactorySpy).toHaveBeenCalledWith( expect(matcherFactorySpy).toHaveBeenCalledWith(
jasmine.any(jasmineUnderTest.MatchersUtil) jasmine.any(jasmineUnderTest.MatchersUtil)
); );
};
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
}); });
it('provides custom equality testers to the matcher factory via matchersUtil', function(done) { it('provides custom equality testers to the matcher factory via matchersUtil', async function() {
const matcherFactory = function(matchersUtil) { const matcherFactory = function(matchersUtil) {
return { return {
compare: function(actual, expected) { compare: function(actual, expected) {
@@ -262,12 +257,13 @@ describe('Custom Matchers (Integration)', function() {
env.expect([1, 2]).toBeArrayWithFirstElement('1'); env.expect([1, 2]).toBeArrayWithFirstElement('1');
}); });
const specExpectations = function(result) { const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter);
await env.execute();
expect(reporter.specDone).toHaveBeenCalledTimes(1);
const result = reporter.specDone.calls.argsFor(0)[0];
expect(customEqualityFn).toHaveBeenCalledWith(1, '1'); expect(customEqualityFn).toHaveBeenCalledWith(1, '1');
expect(result.failedExpectations).toEqual([]); expect(result.failedExpectations).toEqual([]);
};
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
}); });
}); });

View File

@@ -6,7 +6,7 @@ describe('Custom object formatters', function() {
env.configure({ random: false }); env.configure({ random: false });
}); });
it('scopes custom object formatters to a spec', function(done) { it('scopes custom object formatters to a spec', async function() {
env.it('a spec with custom pretty-printer', function() { env.it('a spec with custom pretty-printer', function() {
env.addCustomObjectFormatter(function(obj) { env.addCustomObjectFormatter(function(obj) {
return 'custom(' + obj + ')'; return 'custom(' + obj + ')';
@@ -22,21 +22,19 @@ describe('Custom object formatters', function() {
const specDone = function(result) { const specDone = function(result) {
specResults.push(result); specResults.push(result);
}; };
const expectations = function() { env.addReporter({ specDone: specDone });
await env.execute();
expect(specResults[0].failedExpectations[0].message).toEqual( expect(specResults[0].failedExpectations[0].message).toEqual(
'Expected custom(42) to be undefined.' 'Expected custom(42) to be undefined.'
); );
expect(specResults[1].failedExpectations[0].message).toEqual( expect(specResults[1].failedExpectations[0].message).toEqual(
'Expected 42 to be undefined.' 'Expected 42 to be undefined.'
); );
done();
};
env.addReporter({ specDone: specDone });
env.execute(null, expectations);
}); });
it('scopes custom object formatters to a suite', function(done) { it('scopes custom object formatters to a suite', async function() {
env.it('a spec without custom pretty-printer', function() { env.it('a spec without custom pretty-printer', function() {
env.expect(42).toBeUndefined(); env.expect(42).toBeUndefined();
}); });
@@ -57,18 +55,16 @@ describe('Custom object formatters', function() {
const specDone = function(result) { const specDone = function(result) {
specResults.push(result); specResults.push(result);
}; };
const expectations = function() { env.addReporter({ specDone: specDone });
await env.execute();
expect(specResults[0].failedExpectations[0].message).toEqual( expect(specResults[0].failedExpectations[0].message).toEqual(
'Expected 42 to be undefined.' 'Expected 42 to be undefined.'
); );
expect(specResults[1].failedExpectations[0].message).toEqual( expect(specResults[1].failedExpectations[0].message).toEqual(
'Expected custom(42) to be undefined.' 'Expected custom(42) to be undefined.'
); );
done();
};
env.addReporter({ specDone: specDone });
env.execute(null, expectations);
}); });
it('throws an exception if you try to add a custom object formatter outside a runable', function() { it('throws an exception if you try to add a custom object formatter outside a runable', function() {

View File

@@ -10,7 +10,7 @@ describe('Deprecation (integration)', function() {
env.cleanup_(); env.cleanup_();
}); });
it('reports a deprecation on the top suite', function(done) { it('reports a deprecation on the top suite', async function() {
const reporter = jasmine.createSpyObj('reporter', ['jasmineDone']); const reporter = jasmine.createSpyObj('reporter', ['jasmineDone']);
env.addReporter(reporter); env.addReporter(reporter);
spyOn(console, 'error'); spyOn(console, 'error');
@@ -20,7 +20,8 @@ describe('Deprecation (integration)', function() {
}); });
env.it('a spec', function() {}); env.it('a spec', function() {});
env.execute(null, function() { await env.execute();
expect(reporter.jasmineDone).toHaveBeenCalledWith( expect(reporter.jasmineDone).toHaveBeenCalledWith(
jasmine.objectContaining({ jasmine.objectContaining({
deprecationWarnings: [ deprecationWarnings: [
@@ -33,11 +34,9 @@ describe('Deprecation (integration)', function() {
expect(console.error).toHaveBeenCalledWith( expect(console.error).toHaveBeenCalledWith(
jasmine.stringMatching(/^DEPRECATION: the message/) jasmine.stringMatching(/^DEPRECATION: the message/)
); );
done();
});
}); });
it('reports a deprecation on a descendent suite', function(done) { it('reports a deprecation on a descendent suite', async function() {
const reporter = jasmine.createSpyObj('reporter', ['suiteDone']); const reporter = jasmine.createSpyObj('reporter', ['suiteDone']);
env.addReporter(reporter); env.addReporter(reporter);
spyOn(console, 'error'); spyOn(console, 'error');
@@ -49,7 +48,8 @@ describe('Deprecation (integration)', function() {
env.it('a spec', function() {}); env.it('a spec', function() {});
}); });
env.execute(null, function() { await env.execute();
expect(reporter.suiteDone).toHaveBeenCalledWith( expect(reporter.suiteDone).toHaveBeenCalledWith(
jasmine.objectContaining({ jasmine.objectContaining({
deprecationWarnings: [ deprecationWarnings: [
@@ -60,15 +60,11 @@ describe('Deprecation (integration)', function() {
}) })
); );
expect(console.error).toHaveBeenCalledWith( expect(console.error).toHaveBeenCalledWith(
jasmine.stringMatching( jasmine.stringMatching(/^DEPRECATION: the message \(in suite: a suite\)/)
/^DEPRECATION: the message \(in suite: a suite\)/
)
); );
done();
});
}); });
it('reports a deprecation on a spec', function(done) { it('reports a deprecation on a spec', async function() {
const reporter = jasmine.createSpyObj('reporter', ['specDone']); const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter); env.addReporter(reporter);
spyOn(console, 'error'); spyOn(console, 'error');
@@ -79,7 +75,8 @@ describe('Deprecation (integration)', function() {
}); });
}); });
env.execute(null, function() { await env.execute();
expect(reporter.specDone).toHaveBeenCalledWith( expect(reporter.specDone).toHaveBeenCalledWith(
jasmine.objectContaining({ jasmine.objectContaining({
deprecationWarnings: [ deprecationWarnings: [
@@ -94,11 +91,9 @@ describe('Deprecation (integration)', function() {
/^DEPRECATION: the message \(in spec: a suite a spec\)/ /^DEPRECATION: the message \(in spec: a suite a spec\)/
) )
); );
done();
});
}); });
it('omits the suite or spec context when ignoreRunnable is true', function(done) { it('omits the suite or spec context when ignoreRunnable is true', async function() {
const reporter = jasmine.createSpyObj('reporter', ['jasmineDone']); const reporter = jasmine.createSpyObj('reporter', ['jasmineDone']);
env.addReporter(reporter); env.addReporter(reporter);
spyOn(console, 'error'); spyOn(console, 'error');
@@ -107,7 +102,8 @@ describe('Deprecation (integration)', function() {
env.deprecated('the message', { ignoreRunnable: true }); env.deprecated('the message', { ignoreRunnable: true });
}); });
env.execute(null, function() { await env.execute();
expect(reporter.jasmineDone).toHaveBeenCalledWith( expect(reporter.jasmineDone).toHaveBeenCalledWith(
jasmine.objectContaining({ jasmine.objectContaining({
deprecationWarnings: [ deprecationWarnings: [
@@ -123,11 +119,9 @@ describe('Deprecation (integration)', function() {
expect(console.error).not.toHaveBeenCalledWith( expect(console.error).not.toHaveBeenCalledWith(
jasmine.stringMatching(/a spec/) jasmine.stringMatching(/a spec/)
); );
done();
});
}); });
it('includes the stack trace', function(done) { it('includes the stack trace', async function() {
const reporter = jasmine.createSpyObj('reporter', ['specDone']); const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter); env.addReporter(reporter);
spyOn(console, 'error'); spyOn(console, 'error');
@@ -138,7 +132,8 @@ describe('Deprecation (integration)', function() {
}); });
}); });
env.execute(null, function() { await env.execute();
expect(reporter.specDone).toHaveBeenCalledWith( expect(reporter.specDone).toHaveBeenCalledWith(
jasmine.objectContaining({ jasmine.objectContaining({
deprecationWarnings: [ deprecationWarnings: [
@@ -152,11 +147,9 @@ describe('Deprecation (integration)', function() {
expect(console.error.calls.argsFor(0)[0].replace(/\n/g, 'NL')).toMatch( expect(console.error.calls.argsFor(0)[0].replace(/\n/g, 'NL')).toMatch(
/^DEPRECATION: the message \(in spec: a suite a spec\)NL.*DeprecationSpec.js/ /^DEPRECATION: the message \(in spec: a suite a spec\)NL.*DeprecationSpec.js/
); );
done();
});
}); });
it('excludes the stack trace when omitStackTrace is true', function(done) { it('excludes the stack trace when omitStackTrace is true', async function() {
const reporter = jasmine.createSpyObj('reporter', ['specDone']); const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter); env.addReporter(reporter);
spyOn(console, 'error'); spyOn(console, 'error');
@@ -167,7 +160,8 @@ describe('Deprecation (integration)', function() {
}); });
}); });
env.execute(null, function() { await env.execute();
expect(reporter.specDone).toHaveBeenCalledWith( expect(reporter.specDone).toHaveBeenCalledWith(
jasmine.objectContaining({ jasmine.objectContaining({
deprecationWarnings: [ deprecationWarnings: [
@@ -181,11 +175,9 @@ describe('Deprecation (integration)', function() {
expect(console.error).not.toHaveBeenCalledWith( expect(console.error).not.toHaveBeenCalledWith(
jasmine.stringMatching(/DeprecationSpec.js/) jasmine.stringMatching(/DeprecationSpec.js/)
); );
done();
});
}); });
it('emits a given deprecation only once', function(done) { it('emits a given deprecation only once', async function() {
const reporter = jasmine.createSpyObj('reporter', [ const reporter = jasmine.createSpyObj('reporter', [
'specDone', 'specDone',
'suiteDone' 'suiteDone'
@@ -205,7 +197,8 @@ describe('Deprecation (integration)', function() {
}); });
}); });
env.execute(null, function() { await env.execute();
expect(reporter.suiteDone).toHaveBeenCalledWith( expect(reporter.suiteDone).toHaveBeenCalledWith(
jasmine.objectContaining({ jasmine.objectContaining({
deprecationWarnings: [ deprecationWarnings: [
@@ -228,20 +221,16 @@ describe('Deprecation (integration)', function() {
); );
expect(console.error).toHaveBeenCalledTimes(2); expect(console.error).toHaveBeenCalledTimes(2);
expect(console.error).toHaveBeenCalledWith( expect(console.error).toHaveBeenCalledWith(
jasmine.stringMatching( jasmine.stringMatching(/^DEPRECATION: the message \(in suite: a suite\)/)
/^DEPRECATION: the message \(in suite: a suite\)/
)
); );
expect(console.error).toHaveBeenCalledWith( expect(console.error).toHaveBeenCalledWith(
jasmine.stringMatching( jasmine.stringMatching(
/^DEPRECATION: a different message \(in spec: a suite a spec\)/ /^DEPRECATION: a different message \(in spec: a suite a spec\)/
) )
); );
done();
});
}); });
it('emits a given deprecation each time when config.verboseDeprecations is true', function(done) { it('emits a given deprecation each time when config.verboseDeprecations is true', async function() {
const reporter = jasmine.createSpyObj('reporter', [ const reporter = jasmine.createSpyObj('reporter', [
'specDone', 'specDone',
'suiteDone' 'suiteDone'
@@ -262,7 +251,8 @@ describe('Deprecation (integration)', function() {
}); });
}); });
env.execute(null, function() { await env.execute();
expect(reporter.suiteDone).toHaveBeenCalledWith( expect(reporter.suiteDone).toHaveBeenCalledWith(
jasmine.objectContaining({ jasmine.objectContaining({
deprecationWarnings: [ deprecationWarnings: [
@@ -297,11 +287,9 @@ describe('Deprecation (integration)', function() {
expect(console.error.calls.argsFor(2)[0]).toMatch( expect(console.error.calls.argsFor(2)[0]).toMatch(
/^DEPRECATION: the message \(in spec: a suite a spec\)/ /^DEPRECATION: the message \(in spec: a suite a spec\)/
); );
done();
});
}); });
it('handles deprecations that occur before execute() is called', function(done) { it('handles deprecations that occur before execute() is called', async function() {
const reporter = jasmine.createSpyObj('reporter', ['jasmineDone']); const reporter = jasmine.createSpyObj('reporter', ['jasmineDone']);
env.addReporter(reporter); env.addReporter(reporter);
spyOn(console, 'error'); spyOn(console, 'error');
@@ -309,7 +297,8 @@ describe('Deprecation (integration)', function() {
env.deprecated('the message'); env.deprecated('the message');
env.it('a spec', function() {}); env.it('a spec', function() {});
env.execute(null, function() { await env.execute();
expect(reporter.jasmineDone).toHaveBeenCalledWith( expect(reporter.jasmineDone).toHaveBeenCalledWith(
jasmine.objectContaining({ jasmine.objectContaining({
deprecationWarnings: [ deprecationWarnings: [
@@ -322,7 +311,5 @@ describe('Deprecation (integration)', function() {
expect(console.error).toHaveBeenCalledWith( expect(console.error).toHaveBeenCalledWith(
jasmine.stringMatching(/^DEPRECATION: the message/) jasmine.stringMatching(/^DEPRECATION: the message/)
); );
done();
});
}); });
}); });

View File

@@ -10,12 +10,17 @@ describe('Matchers (Integration)', function() {
}); });
function verifyPasses(expectations) { function verifyPasses(expectations) {
it('passes', function(done) { it('passes', async function() {
env.it('a spec', function() { env.it('a spec', function() {
expectations(env); expectations(env);
}); });
const specExpectations = function(result) { const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter);
await env.execute();
expect(reporter.specDone).toHaveBeenCalledTimes(1);
const result = reporter.specDone.calls.argsFor(0)[0];
expect(result.status).toEqual('passed'); expect(result.status).toEqual('passed');
expect(result.passedExpectations.length) expect(result.passedExpectations.length)
.withContext('Number of passed expectations') .withContext('Number of passed expectations')
@@ -28,28 +33,27 @@ describe('Matchers (Integration)', function() {
) )
.withContext('Failure message') .withContext('Failure message')
.toBeUndefined(); .toBeUndefined();
};
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
}); });
} }
function verifyFails(expectations) { function verifyFails(expectations) {
it('fails', function(done) { it('fails', async function() {
env.it('a spec', function() { env.it('a spec', function() {
expectations(env); expectations(env);
}); });
const specExpectations = function(result) { const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter);
await env.execute();
expect(reporter.specDone).toHaveBeenCalledTimes(1);
const result = reporter.specDone.calls.argsFor(0)[0];
expect(result.status).toEqual('failed'); expect(result.status).toEqual('failed');
expect(result.failedExpectations.length) expect(result.failedExpectations.length)
.withContext('Number of failed expectations') .withContext('Number of failed expectations')
.toEqual(1); .toEqual(1);
expect(result.failedExpectations[0].message) expect(result.failedExpectations[0].message)
.withContext( .withContext('Failed with a thrown error rather than a matcher failure')
'Failed with a thrown error rather than a matcher failure'
)
.not.toMatch(/^Error: /); .not.toMatch(/^Error: /);
expect(result.failedExpectations[0].message) expect(result.failedExpectations[0].message)
.withContext( .withContext(
@@ -59,21 +63,22 @@ describe('Matchers (Integration)', function() {
expect(result.failedExpectations[0].matcherName) expect(result.failedExpectations[0].matcherName)
.withContext('Matcher name') .withContext('Matcher name')
.not.toEqual(''); .not.toEqual('');
};
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
}); });
} }
function verifyFailsWithCustomObjectFormatters(config) { function verifyFailsWithCustomObjectFormatters(config) {
it('uses custom object formatters', function(done) { it('uses custom object formatters', async function() {
env.it('a spec', function() { env.it('a spec', function() {
env.addCustomObjectFormatter(config.formatter); env.addCustomObjectFormatter(config.formatter);
config.expectations(env); config.expectations(env);
}); });
const specExpectations = function(result) { const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter);
await env.execute();
expect(reporter.specDone).toHaveBeenCalledTimes(1);
const result = reporter.specDone.calls.argsFor(0)[0];
expect(result.status).toEqual('failed'); expect(result.status).toEqual('failed');
expect(result.failedExpectations.length) expect(result.failedExpectations.length)
.withContext('Number of failed expectations') .withContext('Number of failed expectations')
@@ -81,20 +86,21 @@ describe('Matchers (Integration)', function() {
expect(result.failedExpectations[0].message).toEqual( expect(result.failedExpectations[0].message).toEqual(
config.expectedMessage config.expectedMessage
); );
};
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
}); });
} }
function verifyPassesAsync(expectations) { function verifyPassesAsync(expectations) {
it('passes', function(done) { it('passes', async function() {
env.it('a spec', function() { env.it('a spec', function() {
return expectations(env); return expectations(env);
}); });
const specExpectations = function(result) { const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter);
await env.execute();
expect(reporter.specDone).toHaveBeenCalledTimes(1);
const result = reporter.specDone.calls.argsFor(0)[0];
expect(result.status).toEqual('passed'); expect(result.status).toEqual('passed');
expect(result.passedExpectations.length) expect(result.passedExpectations.length)
.withContext('Number of passed expectations') .withContext('Number of passed expectations')
@@ -107,48 +113,48 @@ describe('Matchers (Integration)', function() {
) )
.withContext('Failure message') .withContext('Failure message')
.toBeUndefined(); .toBeUndefined();
};
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
}); });
} }
function verifyFailsAsync(expectations) { function verifyFailsAsync(expectations) {
it('fails', function(done) { it('fails', async function() {
env.it('a spec', function() { env.it('a spec', function() {
return expectations(env); return expectations(env);
}); });
const specExpectations = function(result) { const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter);
await env.execute();
expect(reporter.specDone).toHaveBeenCalledTimes(1);
const result = reporter.specDone.calls.argsFor(0)[0];
expect(result.status).toEqual('failed'); expect(result.status).toEqual('failed');
expect(result.failedExpectations.length) expect(result.failedExpectations.length)
.withContext('Number of failed expectations') .withContext('Number of failed expectations')
.toEqual(1); .toEqual(1);
expect(result.failedExpectations[0].message) expect(result.failedExpectations[0].message)
.withContext( .withContext('Failed with a thrown error rather than a matcher failure')
'Failed with a thrown error rather than a matcher failure'
)
.not.toMatch(/^Error: /); .not.toMatch(/^Error: /);
expect(result.failedExpectations[0].matcherName) expect(result.failedExpectations[0].matcherName)
.withContext('Matcher name') .withContext('Matcher name')
.not.toEqual(''); .not.toEqual('');
};
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
}); });
} }
function verifyFailsWithCustomObjectFormattersAsync(config) { function verifyFailsWithCustomObjectFormattersAsync(config) {
it('uses custom object formatters', function(done) { it('uses custom object formatters', async function() {
const env = new jasmineUnderTest.Env(); const env = new jasmineUnderTest.Env();
env.it('a spec', function() { env.it('a spec', function() {
env.addCustomObjectFormatter(config.formatter); env.addCustomObjectFormatter(config.formatter);
return config.expectations(env); return config.expectations(env);
}); });
const specExpectations = function(result) { const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter);
await env.execute();
expect(reporter.specDone).toHaveBeenCalledTimes(1);
const result = reporter.specDone.calls.argsFor(0)[0];
expect(result.status).toEqual('failed'); expect(result.status).toEqual('failed');
expect(result.failedExpectations.length) expect(result.failedExpectations.length)
.withContext('Number of failed expectations') .withContext('Number of failed expectations')
@@ -156,10 +162,6 @@ describe('Matchers (Integration)', function() {
expect(result.failedExpectations[0].message).toEqual( expect(result.failedExpectations[0].message).toEqual(
config.expectedMessage config.expectedMessage
); );
};
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
}); });
} }
@@ -753,12 +755,17 @@ describe('Matchers (Integration)', function() {
}); });
describe('When an async matcher is used with .already()', function() { describe('When an async matcher is used with .already()', function() {
it('propagates the matcher result when the promise is resolved', function(done) { it('propagates the matcher result when the promise is resolved', async function() {
env.it('a spec', function() { env.it('a spec', function() {
return env.expectAsync(Promise.resolve()).already.toBeRejected(); return env.expectAsync(Promise.resolve()).already.toBeRejected();
}); });
const specExpectations = function(result) { const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter);
await env.execute();
expect(reporter.specDone).toHaveBeenCalledTimes(1);
const result = reporter.specDone.calls.argsFor(0)[0];
expect(result.status).toEqual('failed'); expect(result.status).toEqual('failed');
expect(result.failedExpectations.length) expect(result.failedExpectations.length)
.withContext('Number of failed expectations') .withContext('Number of failed expectations')
@@ -769,20 +776,21 @@ describe('Matchers (Integration)', function() {
expect(result.failedExpectations[0].matcherName) expect(result.failedExpectations[0].matcherName)
.withContext('Matcher name') .withContext('Matcher name')
.not.toEqual(''); .not.toEqual('');
};
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
}); });
it('propagates the matcher result when the promise is rejected', function(done) { it('propagates the matcher result when the promise is rejected', async function() {
env.it('a spec', function() { env.it('a spec', function() {
return env return env
.expectAsync(Promise.reject(new Error('nope'))) .expectAsync(Promise.reject(new Error('nope')))
.already.toBeResolved(); .already.toBeResolved();
}); });
const specExpectations = function(result) { const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter);
await env.execute();
expect(reporter.specDone).toHaveBeenCalledTimes(1);
const result = reporter.specDone.calls.argsFor(0)[0];
expect(result.status).toEqual('failed'); expect(result.status).toEqual('failed');
expect(result.failedExpectations.length) expect(result.failedExpectations.length)
.withContext('Number of failed expectations') .withContext('Number of failed expectations')
@@ -794,20 +802,21 @@ describe('Matchers (Integration)', function() {
expect(result.failedExpectations[0].matcherName) expect(result.failedExpectations[0].matcherName)
.withContext('Matcher name') .withContext('Matcher name')
.not.toEqual(''); .not.toEqual('');
};
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
}); });
it('fails when the promise is pending', function(done) { it('fails when the promise is pending', async function() {
const promise = new Promise(function() {}); const promise = new Promise(function() {});
env.it('a spec', function() { env.it('a spec', function() {
return env.expectAsync(promise).already.toBeResolved(); return env.expectAsync(promise).already.toBeResolved();
}); });
const specExpectations = function(result) { const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter);
await env.execute();
expect(reporter.specDone).toHaveBeenCalledTimes(1);
const result = reporter.specDone.calls.argsFor(0)[0];
expect(result.status).toEqual('failed'); expect(result.status).toEqual('failed');
expect(result.failedExpectations.length) expect(result.failedExpectations.length)
.withContext('Number of failed expectations') .withContext('Number of failed expectations')
@@ -819,10 +828,6 @@ describe('Matchers (Integration)', function() {
expect(result.failedExpectations[0].matcherName) expect(result.failedExpectations[0].matcherName)
.withContext('Matcher name') .withContext('Matcher name')
.not.toEqual(''); .not.toEqual('');
};
env.addReporter({ specDone: specExpectations });
env.execute(null, done);
}); });
}); });
}); });