2021-06-09 22:58:05 +09:00
|
|
|
import test from 'ava'
|
|
|
|
|
|
|
|
const bindings = require('../index.node')
|
|
|
|
|
|
|
|
test('should be able to access env variable from native', (t) => {
|
2023-04-06 12:04:53 +09:00
|
|
|
t.is(bindings.getEnvVariable(), '@examples/compat-mode')
|
2021-06-09 22:58:05 +09:00
|
|
|
})
|
2021-11-07 00:33:58 +09:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
2021-11-22 00:10:29 +09:00
|
|
|
|
|
|
|
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))
|
|
|
|
})
|