@sprucelabs/test-utils 5.1.407 → 5.1.408
Sign up to get free protection for your applications and to get access to all the features.
- package/build/assert/assert.js +3 -3
- package/build/assert/assert.utility.d.ts +1 -1
- package/build/assert/assert.utility.js +13 -10
- package/build/esm/assert/assert.js +3 -3
- package/build/esm/assert/assert.utility.d.ts +1 -1
- package/build/esm/assert/assert.utility.js +13 -10
- package/package.json +1 -1
package/build/assert/assert.js
CHANGED
@@ -38,7 +38,7 @@ const assert = {
|
|
38
38
|
}
|
39
39
|
},
|
40
40
|
isNotEqualDeep(actual, expected, message) {
|
41
|
-
this.doesThrow(() => this.isEqualDeep(actual, expected), undefined,
|
41
|
+
this.doesThrow(() => this.isEqualDeep(actual, expected), undefined, buildErrorMessage(`The objects you passed are deep equal! They should not be!`, message));
|
42
42
|
},
|
43
43
|
isAbove(actual, floor, message) {
|
44
44
|
if (typeof actual !== 'number') {
|
@@ -209,7 +209,7 @@ const assert = {
|
|
209
209
|
cb();
|
210
210
|
}
|
211
211
|
catch (err) {
|
212
|
-
assert_utility_1.default.
|
212
|
+
assert_utility_1.default.assertErrorIncludes(matcher, err, msg);
|
213
213
|
return err;
|
214
214
|
}
|
215
215
|
this.fail(buildErrorMessage('Expected a thrown error, but never got one!', msg));
|
@@ -219,7 +219,7 @@ const assert = {
|
|
219
219
|
await cb();
|
220
220
|
}
|
221
221
|
catch (err) {
|
222
|
-
assert_utility_1.default.
|
222
|
+
assert_utility_1.default.assertErrorIncludes(matcher, err, msg);
|
223
223
|
return err;
|
224
224
|
}
|
225
225
|
this.fail(buildErrorMessage('Expected a thrown error, but never got one!', msg));
|
@@ -11,7 +11,7 @@ declare const assertUtil: {
|
|
11
11
|
dropInPlaceholder(obj: Record<string, any>, checker: (obj: any, depth: number) => boolean, placeholder: string, depth?: number): any[] | Record<string, any>;
|
12
12
|
doHaystacksPassCheck(haystacks: any[], needle: any, check: ISpruceAssert["doesInclude"]): boolean;
|
13
13
|
assertTypeof(actual: any, type: string, message: string | undefined): void;
|
14
|
-
|
14
|
+
assertErrorIncludes(matcher: string | RegExp | undefined, err: Error, msg?: string | undefined): void;
|
15
15
|
partialContains(object: any, subObject: any): boolean | undefined;
|
16
16
|
valueAtPath(object: Record<string, any>, path: string): any;
|
17
17
|
parseIncludeNeedle(needle: any): {
|
@@ -116,17 +116,20 @@ const assertUtil = {
|
|
116
116
|
this.fail(message !== null && message !== void 0 ? message : `${JSON.stringify(actual)} is not a ${type}`);
|
117
117
|
}
|
118
118
|
},
|
119
|
-
|
119
|
+
assertErrorIncludes(matcher, err, msg) {
|
120
120
|
var _a;
|
121
|
-
const
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
121
|
+
const originalErrorMessage = (_a = err.message) !== null && _a !== void 0 ? _a : '';
|
122
|
+
const errorMessage = originalErrorMessage.toLowerCase();
|
123
|
+
const needle = typeof matcher === 'string' ? matcher.toLowerCase() : matcher;
|
124
|
+
if (typeof needle === 'string' &&
|
125
|
+
errorMessage.search(needle) === -1 &&
|
126
|
+
!errorMessage.includes(needle)) {
|
127
|
+
this.fail(msg !== null && msg !== void 0 ? msg : `Expected thrown error whose message contains: \n\n${chalk_1.default.bold(matcher)}\n\nbut got back:\n\n\`${chalk_1.default.bold(originalErrorMessage)}\`.`, '\n\nStack: ' + err.stack);
|
128
|
+
}
|
129
|
+
else if (needle instanceof RegExp &&
|
130
|
+
errorMessage.search(needle) === -1 &&
|
131
|
+
originalErrorMessage.search(needle) === -1) {
|
132
|
+
this.fail(msg !== null && msg !== void 0 ? msg : `Expected thrown error whose message matches the regex: \n\n${chalk_1.default.bold(matcher)}\n\nbut got back:\n\n\`${chalk_1.default.bold(originalErrorMessage)}\`.`, '\n\nStack: ' + err.stack);
|
130
133
|
}
|
131
134
|
},
|
132
135
|
partialContains(object, subObject) {
|
@@ -33,7 +33,7 @@ const assert = {
|
|
33
33
|
}
|
34
34
|
},
|
35
35
|
isNotEqualDeep(actual, expected, message) {
|
36
|
-
this.doesThrow(() => this.isEqualDeep(actual, expected), undefined,
|
36
|
+
this.doesThrow(() => this.isEqualDeep(actual, expected), undefined, buildErrorMessage(`The objects you passed are deep equal! They should not be!`, message));
|
37
37
|
},
|
38
38
|
isAbove(actual, floor, message) {
|
39
39
|
if (typeof actual !== 'number') {
|
@@ -204,7 +204,7 @@ const assert = {
|
|
204
204
|
cb();
|
205
205
|
}
|
206
206
|
catch (err) {
|
207
|
-
assertUtil.
|
207
|
+
assertUtil.assertErrorIncludes(matcher, err, msg);
|
208
208
|
return err;
|
209
209
|
}
|
210
210
|
this.fail(buildErrorMessage('Expected a thrown error, but never got one!', msg));
|
@@ -214,7 +214,7 @@ const assert = {
|
|
214
214
|
await cb();
|
215
215
|
}
|
216
216
|
catch (err) {
|
217
|
-
assertUtil.
|
217
|
+
assertUtil.assertErrorIncludes(matcher, err, msg);
|
218
218
|
return err;
|
219
219
|
}
|
220
220
|
this.fail(buildErrorMessage('Expected a thrown error, but never got one!', msg));
|
@@ -11,7 +11,7 @@ declare const assertUtil: {
|
|
11
11
|
dropInPlaceholder(obj: Record<string, any>, checker: (obj: any, depth: number) => boolean, placeholder: string, depth?: number): any[] | Record<string, any>;
|
12
12
|
doHaystacksPassCheck(haystacks: any[], needle: any, check: ISpruceAssert["doesInclude"]): boolean;
|
13
13
|
assertTypeof(actual: any, type: string, message: string | undefined): void;
|
14
|
-
|
14
|
+
assertErrorIncludes(matcher: string | RegExp | undefined, err: Error, msg?: string | undefined): void;
|
15
15
|
partialContains(object: any, subObject: any): boolean | undefined;
|
16
16
|
valueAtPath(object: Record<string, any>, path: string): any;
|
17
17
|
parseIncludeNeedle(needle: any): {
|
@@ -110,17 +110,20 @@ const assertUtil = {
|
|
110
110
|
this.fail(message !== null && message !== void 0 ? message : `${JSON.stringify(actual)} is not a ${type}`);
|
111
111
|
}
|
112
112
|
},
|
113
|
-
|
113
|
+
assertErrorIncludes(matcher, err, msg) {
|
114
114
|
var _a;
|
115
|
-
const
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
115
|
+
const originalErrorMessage = (_a = err.message) !== null && _a !== void 0 ? _a : '';
|
116
|
+
const errorMessage = originalErrorMessage.toLowerCase();
|
117
|
+
const needle = typeof matcher === 'string' ? matcher.toLowerCase() : matcher;
|
118
|
+
if (typeof needle === 'string' &&
|
119
|
+
errorMessage.search(needle) === -1 &&
|
120
|
+
!errorMessage.includes(needle)) {
|
121
|
+
this.fail(msg !== null && msg !== void 0 ? msg : `Expected thrown error whose message contains: \n\n${chalk.bold(matcher)}\n\nbut got back:\n\n\`${chalk.bold(originalErrorMessage)}\`.`, '\n\nStack: ' + err.stack);
|
122
|
+
}
|
123
|
+
else if (needle instanceof RegExp &&
|
124
|
+
errorMessage.search(needle) === -1 &&
|
125
|
+
originalErrorMessage.search(needle) === -1) {
|
126
|
+
this.fail(msg !== null && msg !== void 0 ? msg : `Expected thrown error whose message matches the regex: \n\n${chalk.bold(matcher)}\n\nbut got back:\n\n\`${chalk.bold(originalErrorMessage)}\`.`, '\n\nStack: ' + err.stack);
|
124
127
|
}
|
125
128
|
},
|
126
129
|
partialContains(object, subObject) {
|