napi-rs/examples/napi-compat-mode/__tests__/napi4/deferred.spec.ts

16 lines
431 B
TypeScript
Raw Normal View History

import test from 'ava'
const bindings = require('../../index.node')
test('should resolve deferred from background thread', async (t) => {
const promise = bindings.testDeferred(false)
t.assert(promise instanceof Promise)
const result = await promise
t.is(result, 15)
})
test('should reject deferred from background thread', async (t) => {
await t.throwsAsync(() => bindings.testDeferred(true), { message: 'Fail' })
})