(
err: CsvError | CsvError[],
assert:
| ({ code?: string; message?: string | RegExp | undefined | null } & T)
| ({ code?: string; message?: string | RegExp | undefined | null } & T)[],
exhaustive = false,
)
| 3 | |
| 4 | /* eslint mocha/no-exports: "off" */ |
| 5 | export 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 | |
| 44 | describe("API assert_error", function () { |
| 45 | it("work on array", function () { |
no test coverage detected