MCPcopy Create free account
hub / github.com/nodejs/node-addon-api / test

Function test

test/function_reference.js:130–157  ·  view source on GitHub ↗
(binding)

Source from the content-addressed store, hash-verified

128 );
129}
130async function test (binding) {
131 const e = new Error('foobar');
132 const functionMayThrow = () => {
133 throw e;
134 };
135 const classMayThrow = class {
136 constructor () {
137 throw e;
138 }
139 };
140
141 const newRef = binding.CreateFuncRefWithNew(120);
142 assert(newRef.getValue() === 120);
143
144 const newRefWithVecArg = binding.CreateFuncRefWithNewVec(80);
145 assert(newRefWithVecArg.getValue() === 80);
146
147 assert.throws(() => {
148 binding.call(functionMayThrow);
149 }, /foobar/);
150 assert.throws(() => {
151 binding.construct(classMayThrow);
152 }, /foobar/);
153
154 canConstructRefFromExistingRef(binding);
155 canCallFunctionWithDifferentOverloads(binding);
156 await canCallAsyncFunctionWithDifferentOverloads(binding);
157}

Callers 1

Tested by

no test coverage detected