napi-rs/examples/napi-compat-mode/__tests__/env.spec.ts
forehal a781a4f27e feat(cli): brand new cli tool with both cli and programmatical usage (#1492)
BREAKING CHANGE: requires node >= 16 and some cli options have been renamed
2023-04-06 11:04:53 +08:00

29 lines
827 B
TypeScript

import test from 'ava'
const bindings = require('../index.node')
test('should be able to access env variable from native', (t) => {
t.is(bindings.getEnvVariable(), '@examples/compat-mode')
})
test('should be able to throw syntax error', (t) => {
const msg = 'Custom Syntax Error'
try {
bindings.throwSyntaxError(msg)
throw new Error('Unreachable')
} catch (e) {
t.true(e instanceof SyntaxError)
t.is((e as SyntaxError).message, msg)
}
})
test('should be able to coerceToBool', (t) => {
t.true(bindings.coerceToBool(true))
t.true(bindings.coerceToBool(1))
t.true(bindings.coerceToBool({}))
t.true(bindings.coerceToBool(Symbol()))
t.false(bindings.coerceToBool(0))
t.false(bindings.coerceToBool(undefined))
t.false(bindings.coerceToBool(null))
t.false(bindings.coerceToBool(NaN))
})