napi-rs/test_module/__test__/global.spec.ts

18 lines
404 B
TypeScript
Raw Normal View History

2020-10-03 01:05:43 +09:00
import test from 'ava'
import Sinon from 'sinon'
const bindings = require('../index.node')
function wait(delay: number) {
return new Promise((resolve) => setTimeout(resolve, delay))
}
test('should setTimeout', async (t) => {
const handler = Sinon.spy()
const delay = 100
bindings.setTimeout(handler, delay)
t.is(handler.callCount, 0)
await wait(delay + 10)
t.is(handler.callCount, 1)
})