mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.1 KiB
42 lines
1.1 KiB
8 years ago
|
'use strict';
|
||
|
const common = require('../common');
|
||
|
const assert = require('assert');
|
||
|
const {
|
||
|
createPromise, promiseResolve, promiseReject
|
||
|
} = process.binding('util');
|
||
|
const { inspect } = require('util');
|
||
|
|
||
|
common.crashOnUnhandledRejection();
|
||
|
|
||
|
{
|
||
|
const promise = createPromise();
|
||
|
assert.strictEqual(inspect(promise), 'Promise { <pending> }');
|
||
|
promiseResolve(promise, 42);
|
||
|
assert.strictEqual(inspect(promise), 'Promise { 42 }');
|
||
|
promise.then(common.mustCall((value) => {
|
||
|
assert.strictEqual(value, 42);
|
||
|
}));
|
||
|
}
|
||
|
|
||
|
{
|
||
|
const promise = createPromise();
|
||
|
const error = new Error('foobar');
|
||
|
promiseReject(promise, error);
|
||
|
assert(inspect(promise).includes('<rejected> Error: foobar'));
|
||
|
promise.catch(common.mustCall((value) => {
|
||
|
assert.strictEqual(value, error);
|
||
|
}));
|
||
|
}
|
||
|
|
||
|
{
|
||
|
const promise = createPromise();
|
||
|
const error = new Error('foobar');
|
||
|
promiseReject(promise, error);
|
||
|
assert(inspect(promise).includes('<rejected> Error: foobar'));
|
||
|
promiseResolve(promise, 42);
|
||
|
assert(inspect(promise).includes('<rejected> Error: foobar'));
|
||
|
promise.catch(common.mustCall((value) => {
|
||
|
assert.strictEqual(value, error);
|
||
|
}));
|
||
|
}
|