MCPcopy Create free account
hub / github.com/nodejs/node / assert_same_behavior

Function assert_same_behavior

test/fixtures/wpt/wasm/jsapi/js-string/basic.any.js:135–162  ·  view source on GitHub ↗
(funcA, funcB, ...params)

Source from the content-addressed store, hash-verified

133// A helper function to assert that the behavior of two functions are the
134// same.
135function assert_same_behavior(funcA, funcB, ...params) {
136 let resultA;
137 let errA = null;
138 try {
139 resultA = funcA(...params);
140 } catch (err) {
141 errA = err;
142 }
143
144 let resultB;
145 let errB = null;
146 try {
147 resultB = funcB(...params);
148 } catch (err) {
149 errB = err;
150 }
151
152 if (errA || errB) {
153 assert_equals(errA === null, errB === null, errA ? errA.message : errB.message);
154 assert_equals(Object.getPrototypeOf(errA), Object.getPrototypeOf(errB));
155 }
156 assert_equals(resultA, resultB);
157
158 if (errA) {
159 throw errA;
160 }
161 return resultA;
162}
163
164function assert_throws_if(func, shouldThrow, constructor) {
165 let error = null;

Callers 1

basic.any.jsFile · 0.85

Calls 1

assert_equalsFunction · 0.50

Tested by

no test coverage detected