Skip to content

Commit

Permalink
Fix expect.promise#inspect tests
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Jan 12, 2019
1 parent 7123b8e commit fb72a6b
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions test/api/promise.spec.js
Expand Up @@ -258,6 +258,15 @@ describe('expect.promise', () => {
});
});

let inspectMethodName = 'inspect';
// In node.js 10+ the custom inspect method name has to be given as a symbol
// or we'll get ugly deprecation warnings logged to the console.
try {
const util = require('util');
if (util.inspect.custom) {
inspectMethodName = util.inspect.custom;
}
} catch (err) {}
describe('#inspect', () => {
var originalDefaultFormat = expect.output.constructor.defaultFormat;
beforeEach(() => {
Expand All @@ -273,7 +282,7 @@ describe('expect.promise', () => {
.promise(function() {
expect(2, 'to equal', 2);
})
.inspect(),
[inspectMethodName](),
'to equal',
'Promise (fulfilled)'
);
Expand All @@ -285,7 +294,7 @@ describe('expect.promise', () => {
.promise(function() {
return 123;
})
.inspect(),
[inspectMethodName](),
'to equal',
'Promise (fulfilled) => 123'
);
Expand All @@ -298,7 +307,11 @@ describe('expect.promise', () => {
'to equal',
'foo'
);
expect(asyncPromise.inspect(), 'to equal', 'Promise (pending)');
expect(
asyncPromise[inspectMethodName](),
'to equal',
'Promise (pending)'
);
return asyncPromise;
});

Expand All @@ -308,7 +321,7 @@ describe('expect.promise', () => {
});

return promise.caught(function() {
expect(promise.inspect(), 'to equal', 'Promise (rejected)');
expect(promise[inspectMethodName](), 'to equal', 'Promise (rejected)');
});
});

Expand All @@ -321,7 +334,7 @@ describe('expect.promise', () => {

return promise.caught(function() {
expect(
promise.inspect(),
promise[inspectMethodName](),
'to equal',
"Promise (rejected) => Error('argh')"
);
Expand Down

0 comments on commit fb72a6b

Please sign in to comment.