@naturalcycles/js-lib 14.143.0 → 14.144.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/error/try.d.ts +4 -0
- package/dist/error/try.js +9 -1
- package/dist-esm/error/try.js +7 -0
- package/package.json +1 -1
- package/src/error/try.ts +11 -0
package/dist/error/try.d.ts
CHANGED
|
@@ -57,3 +57,7 @@ export declare function _expectedError<ERR = Error>(fn: AnyFunction, errorClass?
|
|
|
57
57
|
* 2. It does `instanceof` check and throws if wrong Error instance was thrown.
|
|
58
58
|
*/
|
|
59
59
|
export declare function pExpectedError<ERR = Error>(promise: Promise<any>, errorClass?: Class<ERR>): Promise<ERR>;
|
|
60
|
+
/**
|
|
61
|
+
* Shortcut function to simplify error snapshot-matching in tests.
|
|
62
|
+
*/
|
|
63
|
+
export declare function pExpectedErrorString<ERR = Error>(promise: Promise<any>, errorClass?: Class<ERR>): Promise<string>;
|
package/dist/error/try.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pExpectedError = exports._expectedError = exports.UnexpectedPassError = exports.pTry = exports._try = void 0;
|
|
3
|
+
exports.pExpectedErrorString = exports.pExpectedError = exports._expectedError = exports.UnexpectedPassError = exports.pTry = exports._try = void 0;
|
|
4
|
+
const stringifyAny_1 = require("../string/stringifyAny");
|
|
4
5
|
const app_error_1 = require("./app.error");
|
|
5
6
|
/**
|
|
6
7
|
* Calls a function, returns a Tuple of [error, value].
|
|
@@ -109,3 +110,10 @@ async function pExpectedError(promise, errorClass) {
|
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
112
|
exports.pExpectedError = pExpectedError;
|
|
113
|
+
/**
|
|
114
|
+
* Shortcut function to simplify error snapshot-matching in tests.
|
|
115
|
+
*/
|
|
116
|
+
async function pExpectedErrorString(promise, errorClass) {
|
|
117
|
+
return (0, stringifyAny_1._stringifyAny)(await pExpectedError(promise, errorClass));
|
|
118
|
+
}
|
|
119
|
+
exports.pExpectedErrorString = pExpectedErrorString;
|
package/dist-esm/error/try.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _stringifyAny } from '../string/stringifyAny';
|
|
1
2
|
import { AppError } from './app.error';
|
|
2
3
|
/**
|
|
3
4
|
* Calls a function, returns a Tuple of [error, value].
|
|
@@ -101,3 +102,9 @@ export async function pExpectedError(promise, errorClass) {
|
|
|
101
102
|
return err; // this is expected!
|
|
102
103
|
}
|
|
103
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Shortcut function to simplify error snapshot-matching in tests.
|
|
107
|
+
*/
|
|
108
|
+
export async function pExpectedErrorString(promise, errorClass) {
|
|
109
|
+
return _stringifyAny(await pExpectedError(promise, errorClass));
|
|
110
|
+
}
|
package/package.json
CHANGED
package/src/error/try.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _stringifyAny } from '../string/stringifyAny'
|
|
1
2
|
import type { Class } from '../typeFest'
|
|
2
3
|
import type { AnyFunction } from '../types'
|
|
3
4
|
import { AppError } from './app.error'
|
|
@@ -113,3 +114,13 @@ export async function pExpectedError<ERR = Error>(
|
|
|
113
114
|
return err as ERR // this is expected!
|
|
114
115
|
}
|
|
115
116
|
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Shortcut function to simplify error snapshot-matching in tests.
|
|
120
|
+
*/
|
|
121
|
+
export async function pExpectedErrorString<ERR = Error>(
|
|
122
|
+
promise: Promise<any>,
|
|
123
|
+
errorClass?: Class<ERR>,
|
|
124
|
+
): Promise<string> {
|
|
125
|
+
return _stringifyAny(await pExpectedError<ERR>(promise, errorClass))
|
|
126
|
+
}
|