MCPcopy Index your code
hub / github.com/nodejs/node / expectError

Function expectError

test/parallel/test-stream-writable-write-error.js:7–28  ·  view source on GitHub ↗
(w, args, code, sync)

Source from the content-addressed store, hash-verified

5const { Writable } = require('stream');
6
7function expectError(w, args, code, sync) {
8 if (sync) {
9 if (code) {
10 assert.throws(() => w.write(...args), { code });
11 } else {
12 w.write(...args);
13 }
14 } else {
15 let errorCalled = false;
16 let ticked = false;
17 w.write(...args, common.mustCall((err) => {
18 assert.strictEqual(ticked, true);
19 assert.strictEqual(errorCalled, false);
20 assert.strictEqual(err.code, code);
21 }));
22 ticked = true;
23 w.on('error', common.mustCall((err) => {
24 errorCalled = true;
25 assert.strictEqual(err.code, code);
26 }));
27 }
28}
29
30function test(autoDestroy) {
31 {

Callers 1

testFunction · 0.85

Calls 2

writeMethod · 0.45
onMethod · 0.45

Tested by 1

testFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…