|
1 | 1 | import { assert } from "chai";
|
2 | 2 | import { postcss } from "opticss";
|
3 | 3 |
|
4 |
| -import { MultipleCssBlockErrors } from "../../src"; |
| 4 | +import { CssBlockError, MultipleCssBlockErrors } from "../../src"; |
5 | 5 | import cssBlocks from ".././util/postcss-helper";
|
6 | 6 |
|
7 | 7 | export interface ErrorTypeMessage {
|
@@ -39,12 +39,16 @@ export function assertMultipleErrors(errors: ErrorTypeMessage[], promise: postcs
|
39 | 39 | (multipleErrorsError: MultipleCssBlockErrors) => assertMultipleErrorsWithoutPromise(multipleErrorsError, errors));
|
40 | 40 | }
|
41 | 41 |
|
42 |
| -export function assertMultipleErrorsWithoutPromise(multipleErrorsError: MultipleCssBlockErrors, errors: ErrorTypeMessage[]) { |
43 |
| - if (multipleErrorsError.errors.length !== errors.length) { |
44 |
| - assert(false, "The number of errors thrown and expected does not match"); |
| 42 | +export function assertMultipleErrorsWithoutPromise(mainError: CssBlockError, errors: ErrorTypeMessage[]) { |
| 43 | + if (mainError instanceof MultipleCssBlockErrors) { |
| 44 | + assert.equal(mainError.errors.length, errors.length, "The number of errors thrown and expected does not match"); |
| 45 | + errors.forEach((error, idx) => { |
| 46 | + assert(mainError.errors[idx] instanceof error.type, "Error raised was not of the type expected."); |
| 47 | + assert.deepEqual(mainError.errors[idx].message.split(error.type.prefix + ":")[1].trim(), error.message); |
| 48 | + }); |
| 49 | + } else { |
| 50 | + assert.equal(1, errors.length, "The number of errors thrown and expected does not match"); |
| 51 | + assert(mainError instanceof errors[0].type, "Error raised was not of the type expected."); |
| 52 | + assert.deepEqual(mainError.message.split(errors[0].type.prefix + ":")[1].trim(), errors[0].message); |
45 | 53 | }
|
46 |
| - return errors.forEach((error, idx) => { |
47 |
| - assert(error.type.name, typeof multipleErrorsError.errors[idx]); |
48 |
| - assert.deepEqual(multipleErrorsError.errors[idx].message.split(error.type.prefix + ":")[1].trim(), error.message); |
49 |
| - }); |
50 | 54 | }
|
0 commit comments