MCPcopy
hub / github.com/adaltas/node-csv / assert_error

Function assert_error

packages/csv-parse/test/api.assert_error.ts:5–42  ·  view source on GitHub ↗
(
  err: CsvError | CsvError[],
  assert:
    | ({ code?: string; message?: string | RegExp | undefined | null } & T)
    | ({ code?: string; message?: string | RegExp | undefined | null } & T)[],
  exhaustive = false,
)

Source from the content-addressed store, hash-verified

3
4/* eslint mocha/no-exports: "off" */
5export const assert_error = function <T>(
6 err: CsvError | CsvError[],
7 assert:
8 | ({ code?: string; message?: string | RegExp | undefined | null } & T)
9 | ({ code?: string; message?: string | RegExp | undefined | null } & T)[],
10 exhaustive = false,
11) {
12 if (Array.isArray(err)) {
13 err.forEach((e, i) =>
14 assert_error(e, Array.isArray(assert) ? assert[i] : assert),
15 );
16 return;
17 }
18 if (exhaustive) {
19 for (const key in err) {
20 assert.should.have.keys(key);
21 }
22 }
23 err.should.be.an.Error();
24 for (const [key, expect] of Object.entries(assert)) {
25 let value = err[key];
26 if (typeof expect === "string") {
27 // eg, convert a buffer
28 if (value?.toString) {
29 value = value.toString();
30 }
31 should(value).deepEqual(expect);
32 } else if (expect instanceof RegExp) {
33 should(value).match(expect);
34 } else if (expect === undefined) {
35 should(value).be.undefined();
36 } else if (expect === null) {
37 should(value).be.null();
38 } else {
39 should(value).deepEqual(expect);
40 }
41 }
42};
43
44describe("API assert_error", function () {
45 it("work on array", function () {

Callers 15

option.rtrim.tsFile · 0.85
option.columns.tsFile · 0.85
option.bom.tsFile · 0.85
info.lines.tsFile · 0.85
option.ltrim.tsFile · 0.85
option.cast.tsFile · 0.85
option.columns.jsFile · 0.85
option.on_skip.tsFile · 0.85

Calls 1

toStringMethod · 0.80

Tested by

no test coverage detected