2020-08-24 17:16:35 +09:00
|
|
|
import test from 'ava'
|
2020-07-03 01:36:45 +09:00
|
|
|
|
|
|
|
const bindings = require('../index.node')
|
|
|
|
|
2020-07-03 01:31:50 +09:00
|
|
|
test('should call the function', (t) => {
|
2020-08-24 17:16:35 +09:00
|
|
|
bindings.testCallFunction((arg1: string, arg2: string) => {
|
2020-07-03 01:31:50 +09:00
|
|
|
t.is(`${arg1} ${arg2}`, 'hello world')
|
2020-07-03 01:36:45 +09:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-01 19:50:38 +09:00
|
|
|
test('should call function with ref args', (t) => {
|
|
|
|
bindings.testCallFunctionWithRefArguments((arg1: string, arg2: string) => {
|
|
|
|
t.is(`${arg1} ${arg2}`, 'hello world')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-07-03 01:31:50 +09:00
|
|
|
test('should set "this" properly', (t) => {
|
2020-07-03 01:36:45 +09:00
|
|
|
const obj = {}
|
2020-08-24 17:16:35 +09:00
|
|
|
bindings.testCallFunctionWithThis.call(obj, function (this: typeof obj) {
|
2020-07-03 01:31:50 +09:00
|
|
|
t.is(this, obj)
|
2020-07-03 01:36:45 +09:00
|
|
|
})
|
|
|
|
})
|
2022-09-14 18:03:11 +09:00
|
|
|
|
|
|
|
test('should handle errors', (t) => {
|
|
|
|
bindings.testCallFunctionError(
|
|
|
|
() => {
|
|
|
|
throw new Error('Testing')
|
|
|
|
},
|
|
|
|
(err: Error) => {
|
|
|
|
t.is(err.message, 'Testing')
|
|
|
|
},
|
|
|
|
)
|
|
|
|
})
|