Skip to content

Commit

Permalink
test: Add promise unit test (#1173)
Browse files Browse the repository at this point in the history
* Add promise unit test
  • Loading branch information
kevindavies8 committed May 13, 2022
1 parent 08cd71a commit 67ce0e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/promise.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@ Value RejectPromise(const CallbackInfo& info) {
return deferred.Promise();
}

Value PromiseReturnsCorrectEnv(const CallbackInfo& info) {
auto deferred = Promise::Deferred::New(info.Env());
return Boolean::New(info.Env(), deferred.Env() == info.Env());
}

Object InitPromise(Env env) {
Object exports = Object::New(env);

exports["isPromise"] = Function::New(env, IsPromise);
exports["resolvePromise"] = Function::New(env, ResolvePromise);
exports["rejectPromise"] = Function::New(env, RejectPromise);
exports["promiseReturnsCorrectEnv"] =
Function::New(env, PromiseReturnsCorrectEnv);

return exports;
}
2 changes: 2 additions & 0 deletions test/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ async function test (binding) {
const rejecting = binding.promise.rejectPromise('error');
await assert.strictEqual(binding.promise.isPromise(rejecting), true);
rejecting.then(common.mustNotCall()).catch(common.mustCall());

assert(binding.promise.promiseReturnsCorrectEnv());
}

0 comments on commit 67ce0e5

Please sign in to comment.