Skip to content

Commit e8aefd2

Browse files
authored
test: fix error message checking (#171)
1 parent bbbe909 commit e8aefd2

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

packages/config-array/tests/config-array.test.js

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -310,28 +310,15 @@ describe("ConfigArray", () => {
310310
basePath,
311311
});
312312

313-
let actualError;
314-
try {
315-
await configArray.normalize();
316-
} catch (error) {
317-
actualError = error;
318-
}
319-
assert.throws(() => {
320-
if (actualError) {
321-
throw actualError;
322-
}
323-
}, expectedError.message);
313+
await assert.rejects(configArray.normalize(), expectedError);
324314
});
325315

326316
localIt(`${title} when calling normalizeSync()`, () => {
327317
const configArray = new ConfigArray(configsToTest, {
328318
basePath,
329319
});
330320

331-
assert.throws(
332-
() => configArray.normalizeSync(),
333-
expectedError.message,
334-
);
321+
assert.throws(() => configArray.normalizeSync(), expectedError);
335322
});
336323
}
337324

@@ -374,7 +361,7 @@ describe("ConfigArray", () => {
374361
},
375362
],
376363
expectedError:
377-
'Config Error: Config (unnamed): Key "files": Items must be a string, a function, or an array of strings and functions.',
364+
/ConfigError: Config \(unnamed\): Key "files": Items must be a string, a function, or an array of strings and functions\./u,
378365
});
379366

380367
testValidationError({
@@ -385,7 +372,7 @@ describe("ConfigArray", () => {
385372
},
386373
],
387374
expectedError:
388-
'Config Error: Config (unnamed): Key "ignores": Expected value to be an array.',
375+
/ConfigError: Config \(unnamed\): Key "ignores": Expected value to be an array\./u,
389376
});
390377

391378
testValidationError({
@@ -397,7 +384,7 @@ describe("ConfigArray", () => {
397384
},
398385
],
399386
expectedError:
400-
'Config "foo": Key "ignores": Expected array to only contain strings and functions.',
387+
/Config "foo": Key "ignores": Expected array to only contain strings and functions\./u,
401388
});
402389

403390
testValidationError({
@@ -410,7 +397,7 @@ describe("ConfigArray", () => {
410397
},
411398
],
412399
expectedError:
413-
'Config "foo": Key "ignores": Expected array to only contain strings and functions.',
400+
/Config "foo": Key "ignores": Expected array to only contain strings and functions\./u,
414401
});
415402

416403
it("should throw an error when a config is not an object", () => {

0 commit comments

Comments
 (0)