@wordpress/jest-console 8.34.0 → 8.34.1-next.2f1c7c01b.0
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/build/index.js +3 -1
- package/build/index.js.map +1 -1
- package/build/matchers.js +6 -4
- package/build/matchers.js.map +1 -1
- package/build/supported-matchers.js +3 -1
- package/build/supported-matchers.js.map +1 -1
- package/build/types.js +2 -0
- package/build/types.js.map +1 -1
- package/build-module/index.js +2 -1
- package/build-module/index.js.map +1 -1
- package/build-module/matchers.js +5 -4
- package/build-module/matchers.js.map +1 -1
- package/build-module/supported-matchers.js +2 -1
- package/build-module/supported-matchers.js.map +1 -1
- package/package.json +2 -2
package/build/index.js
CHANGED
|
@@ -21,9 +21,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
22
|
mod
|
|
23
23
|
));
|
|
24
|
+
|
|
25
|
+
// packages/jest-console/src/index.ts
|
|
24
26
|
var import_matchers = require("./matchers");
|
|
25
27
|
var import_supported_matchers = __toESM(require("./supported-matchers"));
|
|
26
|
-
|
|
28
|
+
var setConsoleMethodSpy = (args) => {
|
|
27
29
|
const [methodName, matcherName] = args;
|
|
28
30
|
const spy = jest.spyOn(console, methodName).mockName(`console.${methodName}`);
|
|
29
31
|
function resetSpy() {
|
package/build/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport './matchers';\nimport supportedMatchers from './supported-matchers';\nimport type { ExtendedMock } from './types';\n\n/**\n * Sets spy on the console object's method to make it possible to fail test when method called without assertion.\n *\n * @param args\n */\nconst setConsoleMethodSpy = ( args: [ string, string ] ) => {\n\tconst [ methodName, matcherName ] = args;\n\tconst spy = jest\n\t\t.spyOn( console, methodName as 'error' | 'info' | 'log' | 'warn' )\n\t\t.mockName( `console.${ methodName }` ) as ExtendedMock;\n\n\t/**\n\t * Resets the spy to its initial state.\n\t */\n\tfunction resetSpy() {\n\t\tspy.mockReset();\n\t\tspy.assertionsNumber = 0;\n\t}\n\n\t/**\n\t * Verifies that the spy has only been called if expected.\n\t */\n\tfunction assertExpectedCalls() {\n\t\tif ( spy.assertionsNumber === 0 && spy.mock.calls.length > 0 ) {\n\t\t\texpect( console ).not[ matcherName ]();\n\t\t}\n\t}\n\n\tbeforeAll( resetSpy );\n\n\tbeforeEach( () => {\n\t\tassertExpectedCalls();\n\t\tresetSpy();\n\t} );\n\n\tafterEach( assertExpectedCalls );\n};\n\nObject.entries( supportedMatchers ).forEach( setConsoleMethodSpy );\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAGA,sBAAO;AACP,gCAA8B;AAQ9B,IAAM,sBAAsB,CAAE,SAA8B;AAC3D,QAAM,CAAE,YAAY,WAAY,IAAI;AACpC,QAAM,MAAM,KACV,MAAO,SAAS,UAAgD,EAChE,SAAU,WAAY,UAAW,EAAG;AAKtC,WAAS,WAAW;AACnB,QAAI,UAAU;AACd,QAAI,mBAAmB;AAAA,EACxB;AAKA,WAAS,sBAAsB;AAC9B,QAAK,IAAI,qBAAqB,KAAK,IAAI,KAAK,MAAM,SAAS,GAAI;AAC9D,aAAQ,OAAQ,EAAE,IAAK,WAAY,EAAE;AAAA,IACtC;AAAA,EACD;AAEA,YAAW,QAAS;AAEpB,aAAY,MAAM;AACjB,wBAAoB;AACpB,aAAS;AAAA,EACV,CAAE;AAEF,YAAW,mBAAoB;AAChC;AAEA,OAAO,QAAS,0BAAAA,OAAkB,EAAE,QAAS,mBAAoB;",
|
|
6
6
|
"names": ["supportedMatchers"]
|
|
7
7
|
}
|
package/build/matchers.js
CHANGED
|
@@ -21,9 +21,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
22
|
mod
|
|
23
23
|
));
|
|
24
|
+
|
|
25
|
+
// packages/jest-console/src/matchers.ts
|
|
24
26
|
var import_jest_matcher_utils = require("jest-matcher-utils");
|
|
25
27
|
var import_supported_matchers = __toESM(require("./supported-matchers"));
|
|
26
|
-
|
|
28
|
+
var createErrorMessage = (spyInfo) => {
|
|
27
29
|
const { spy, pass, calls, matcherName, methodName, expected } = spyInfo;
|
|
28
30
|
const hint = pass ? `.not${matcherName}` : matcherName;
|
|
29
31
|
const message = pass ? `Expected mock function not to be called but it was called with:
|
|
@@ -41,7 +43,7 @@ ${calls.map(import_jest_matcher_utils.printReceived)}`;
|
|
|
41
43
|
console.${methodName}() should not be used unless explicitly expected
|
|
42
44
|
See https://www.npmjs.com/package/@wordpress/jest-console for details.`;
|
|
43
45
|
};
|
|
44
|
-
|
|
46
|
+
var createSpyInfo = (spy, matcherName, methodName, expected) => {
|
|
45
47
|
const calls = spy.mock.calls;
|
|
46
48
|
const pass = expected ? JSON.stringify(calls).includes(JSON.stringify(expected)) : calls.length > 0;
|
|
47
49
|
const message = createErrorMessage({
|
|
@@ -57,13 +59,13 @@ const createSpyInfo = (spy, matcherName, methodName, expected) => {
|
|
|
57
59
|
message
|
|
58
60
|
};
|
|
59
61
|
};
|
|
60
|
-
|
|
62
|
+
var createToHaveBeenCalledMatcher = (matcherName, methodName) => (received) => {
|
|
61
63
|
const spy = received[methodName];
|
|
62
64
|
const spyInfo = createSpyInfo(spy, matcherName, methodName);
|
|
63
65
|
spy.assertionsNumber += 1;
|
|
64
66
|
return spyInfo;
|
|
65
67
|
};
|
|
66
|
-
|
|
68
|
+
var createToHaveBeenCalledWith = (matcherName, methodName) => function(received, ...expected) {
|
|
67
69
|
const spy = received[methodName];
|
|
68
70
|
const spyInfo = createSpyInfo(spy, matcherName, methodName, expected);
|
|
69
71
|
spy.assertionsNumber += 1;
|
package/build/matchers.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/matchers.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * External dependencies\n */\nimport { matcherHint, printExpected, printReceived } from 'jest-matcher-utils';\n\n/**\n * Internal dependencies\n */\nimport supportedMatchers from './supported-matchers';\nimport type { Mock } from 'jest-mock';\nimport type {\n\tExtendedMock,\n\tMatcherFunction,\n\tMatcherResult,\n\tMatcherWithArgsFunction,\n} from './types';\n\ninterface SpyInfo {\n\tspy: Mock;\n\tpass: boolean;\n\tcalls: unknown[][];\n\tmatcherName: string;\n\tmethodName: string;\n\texpected?: unknown[];\n}\n\nconst createErrorMessage = ( spyInfo: SpyInfo ) => {\n\tconst { spy, pass, calls, matcherName, methodName, expected } = spyInfo;\n\tconst hint = pass ? `.not${ matcherName }` : matcherName;\n\tconst message = pass\n\t\t? `Expected mock function not to be called but it was called with:\\n${ calls.map(\n\t\t\t\tprintReceived\n\t\t ) }`\n\t\t: `Expected mock function to be called${\n\t\t\t\texpected ? ` with:\\n${ printExpected( expected ) }\\n` : '.'\n\t\t }\\nbut it was called with:\\n${ calls.map( printReceived ) }`;\n\n\treturn () =>\n\t\t`${ matcherHint( hint, spy.getMockName() ) }` +\n\t\t'\\n\\n' +\n\t\tmessage +\n\t\t'\\n\\n' +\n\t\t`console.${ methodName }() should not be used unless explicitly expected\\n` +\n\t\t'See https://www.npmjs.com/package/@wordpress/jest-console for details.';\n};\n\nconst createSpyInfo = (\n\tspy: Mock,\n\tmatcherName: string,\n\tmethodName: string,\n\texpected?: unknown[]\n) => {\n\tconst calls = spy.mock.calls;\n\n\tconst pass = expected\n\t\t? JSON.stringify( calls ).includes( JSON.stringify( expected ) )\n\t\t: calls.length > 0;\n\n\tconst message = createErrorMessage( {\n\t\tspy,\n\t\tpass,\n\t\tcalls,\n\t\tmatcherName,\n\t\tmethodName,\n\t\texpected,\n\t} );\n\n\treturn {\n\t\tpass,\n\t\tmessage,\n\t};\n};\n\nconst createToHaveBeenCalledMatcher =\n\t( matcherName: string, methodName: string ) =>\n\t( received: Record< string, Mock > ): MatcherResult => {\n\t\tconst spy = received[ methodName ] as ExtendedMock;\n\t\tconst spyInfo = createSpyInfo( spy, matcherName, methodName );\n\t\tspy.assertionsNumber += 1;\n\t\treturn spyInfo;\n\t};\n\nconst createToHaveBeenCalledWith = (\n\tmatcherName: string,\n\tmethodName: string\n) =>\n\tfunction (\n\t\treceived: Record< string, Mock >,\n\t\t...expected: unknown[]\n\t): MatcherResult {\n\t\tconst spy = received[ methodName ] as ExtendedMock;\n\t\tconst spyInfo = createSpyInfo( spy, matcherName, methodName, expected );\n\t\tspy.assertionsNumber += 1;\n\t\treturn spyInfo;\n\t};\n\ntype MatchersObject = Record<\n\tstring,\n\tMatcherFunction | MatcherWithArgsFunction\n>;\n\nexpect.extend(\n\tObject.entries( supportedMatchers ).reduce< MatchersObject >(\n\t\t( result, [ methodName, matcherName ] ) => {\n\t\t\tconst matcherNameWith = `${ matcherName }With`;\n\n\t\t\treturn {\n\t\t\t\t...result,\n\t\t\t\t[ matcherName ]: createToHaveBeenCalledMatcher(\n\t\t\t\t\t`.${ matcherName }`,\n\t\t\t\t\tmethodName\n\t\t\t\t),\n\t\t\t\t[ matcherNameWith ]: createToHaveBeenCalledWith(\n\t\t\t\t\t`.${ matcherNameWith }`,\n\t\t\t\t\tmethodName\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t{}\n\t)\n);\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAGA,gCAA0D;AAK1D,gCAA8B;AAkB9B,IAAM,qBAAqB,CAAE,YAAsB;AAClD,QAAM,EAAE,KAAK,MAAM,OAAO,aAAa,YAAY,SAAS,IAAI;AAChE,QAAM,OAAO,OAAO,OAAQ,WAAY,KAAK;AAC7C,QAAM,UAAU,OACb;A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,eAAgB;AAAA,UACrB;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAC;AAAA,EACF;AACD;",
|
|
6
6
|
"names": ["supportedMatchers"]
|
|
7
7
|
}
|
|
@@ -16,12 +16,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/jest-console/src/supported-matchers.ts
|
|
19
21
|
var supported_matchers_exports = {};
|
|
20
22
|
__export(supported_matchers_exports, {
|
|
21
23
|
default: () => supported_matchers_default
|
|
22
24
|
});
|
|
23
25
|
module.exports = __toCommonJS(supported_matchers_exports);
|
|
24
|
-
|
|
26
|
+
var supportedMatchers = {
|
|
25
27
|
error: "toHaveErrored",
|
|
26
28
|
info: "toHaveInformed",
|
|
27
29
|
log: "toHaveLogged",
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/supported-matchers.ts"],
|
|
4
4
|
"sourcesContent": ["const supportedMatchers: Record< string, string > = {\n\terror: 'toHaveErrored',\n\tinfo: 'toHaveInformed',\n\tlog: 'toHaveLogged',\n\twarn: 'toHaveWarned',\n};\n\nexport default supportedMatchers;\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAM,oBAA8C;AAAA,EACnD,OAAO;AAAA,EACP,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AACP;AAEA,IAAO,6BAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/types.js
CHANGED
|
@@ -12,6 +12,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
12
12
|
return to;
|
|
13
13
|
};
|
|
14
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// packages/jest-console/src/types.ts
|
|
15
17
|
var types_exports = {};
|
|
16
18
|
module.exports = __toCommonJS(types_exports);
|
|
17
19
|
//# sourceMappingURL=types.js.map
|
package/build/types.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/types.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { Mock } from 'jest-mock';\n\n/**\n * Interface for the extended Jest Mock that includes the assertionsNumber property\n */\nexport interface ExtendedMock extends Mock {\n\tassertionsNumber: number;\n}\n\n/**\n * Interface for the matcher result object\n */\nexport interface MatcherResult {\n\tpass: boolean;\n\tmessage: () => string;\n}\n\n/**\n * Interface for the matcher function\n */\nexport type MatcherFunction = (\n\treceived: Record< string, Mock >\n) => MatcherResult;\n\n/**\n * Interface for the matcher function with arguments\n */\nexport type MatcherWithArgsFunction = (\n\treceived: Record< string, Mock >,\n\t...expected: unknown[]\n) => MatcherResult;\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build-module/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
// packages/jest-console/src/index.ts
|
|
1
2
|
import "./matchers";
|
|
2
3
|
import supportedMatchers from "./supported-matchers";
|
|
3
|
-
|
|
4
|
+
var setConsoleMethodSpy = (args) => {
|
|
4
5
|
const [methodName, matcherName] = args;
|
|
5
6
|
const spy = jest.spyOn(console, methodName).mockName(`console.${methodName}`);
|
|
6
7
|
function resetSpy() {
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport './matchers';\nimport supportedMatchers from './supported-matchers';\nimport type { ExtendedMock } from './types';\n\n/**\n * Sets spy on the console object's method to make it possible to fail test when method called without assertion.\n *\n * @param args\n */\nconst setConsoleMethodSpy = ( args: [ string, string ] ) => {\n\tconst [ methodName, matcherName ] = args;\n\tconst spy = jest\n\t\t.spyOn( console, methodName as 'error' | 'info' | 'log' | 'warn' )\n\t\t.mockName( `console.${ methodName }` ) as ExtendedMock;\n\n\t/**\n\t * Resets the spy to its initial state.\n\t */\n\tfunction resetSpy() {\n\t\tspy.mockReset();\n\t\tspy.assertionsNumber = 0;\n\t}\n\n\t/**\n\t * Verifies that the spy has only been called if expected.\n\t */\n\tfunction assertExpectedCalls() {\n\t\tif ( spy.assertionsNumber === 0 && spy.mock.calls.length > 0 ) {\n\t\t\texpect( console ).not[ matcherName ]();\n\t\t}\n\t}\n\n\tbeforeAll( resetSpy );\n\n\tbeforeEach( () => {\n\t\tassertExpectedCalls();\n\t\tresetSpy();\n\t} );\n\n\tafterEach( assertExpectedCalls );\n};\n\nObject.entries( supportedMatchers ).forEach( setConsoleMethodSpy );\n"],
|
|
5
|
-
"mappings": "AAGA,OAAO;AACP,OAAO,uBAAuB;AAQ9B,
|
|
5
|
+
"mappings": ";AAGA,OAAO;AACP,OAAO,uBAAuB;AAQ9B,IAAM,sBAAsB,CAAE,SAA8B;AAC3D,QAAM,CAAE,YAAY,WAAY,IAAI;AACpC,QAAM,MAAM,KACV,MAAO,SAAS,UAAgD,EAChE,SAAU,WAAY,UAAW,EAAG;AAKtC,WAAS,WAAW;AACnB,QAAI,UAAU;AACd,QAAI,mBAAmB;AAAA,EACxB;AAKA,WAAS,sBAAsB;AAC9B,QAAK,IAAI,qBAAqB,KAAK,IAAI,KAAK,MAAM,SAAS,GAAI;AAC9D,aAAQ,OAAQ,EAAE,IAAK,WAAY,EAAE;AAAA,IACtC;AAAA,EACD;AAEA,YAAW,QAAS;AAEpB,aAAY,MAAM;AACjB,wBAAoB;AACpB,aAAS;AAAA,EACV,CAAE;AAEF,YAAW,mBAAoB;AAChC;AAEA,OAAO,QAAS,iBAAkB,EAAE,QAAS,mBAAoB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build-module/matchers.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
// packages/jest-console/src/matchers.ts
|
|
1
2
|
import { matcherHint, printExpected, printReceived } from "jest-matcher-utils";
|
|
2
3
|
import supportedMatchers from "./supported-matchers";
|
|
3
|
-
|
|
4
|
+
var createErrorMessage = (spyInfo) => {
|
|
4
5
|
const { spy, pass, calls, matcherName, methodName, expected } = spyInfo;
|
|
5
6
|
const hint = pass ? `.not${matcherName}` : matcherName;
|
|
6
7
|
const message = pass ? `Expected mock function not to be called but it was called with:
|
|
@@ -18,7 +19,7 @@ ${calls.map(printReceived)}`;
|
|
|
18
19
|
console.${methodName}() should not be used unless explicitly expected
|
|
19
20
|
See https://www.npmjs.com/package/@wordpress/jest-console for details.`;
|
|
20
21
|
};
|
|
21
|
-
|
|
22
|
+
var createSpyInfo = (spy, matcherName, methodName, expected) => {
|
|
22
23
|
const calls = spy.mock.calls;
|
|
23
24
|
const pass = expected ? JSON.stringify(calls).includes(JSON.stringify(expected)) : calls.length > 0;
|
|
24
25
|
const message = createErrorMessage({
|
|
@@ -34,13 +35,13 @@ const createSpyInfo = (spy, matcherName, methodName, expected) => {
|
|
|
34
35
|
message
|
|
35
36
|
};
|
|
36
37
|
};
|
|
37
|
-
|
|
38
|
+
var createToHaveBeenCalledMatcher = (matcherName, methodName) => (received) => {
|
|
38
39
|
const spy = received[methodName];
|
|
39
40
|
const spyInfo = createSpyInfo(spy, matcherName, methodName);
|
|
40
41
|
spy.assertionsNumber += 1;
|
|
41
42
|
return spyInfo;
|
|
42
43
|
};
|
|
43
|
-
|
|
44
|
+
var createToHaveBeenCalledWith = (matcherName, methodName) => function(received, ...expected) {
|
|
44
45
|
const spy = received[methodName];
|
|
45
46
|
const spyInfo = createSpyInfo(spy, matcherName, methodName, expected);
|
|
46
47
|
spy.assertionsNumber += 1;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/matchers.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * External dependencies\n */\nimport { matcherHint, printExpected, printReceived } from 'jest-matcher-utils';\n\n/**\n * Internal dependencies\n */\nimport supportedMatchers from './supported-matchers';\nimport type { Mock } from 'jest-mock';\nimport type {\n\tExtendedMock,\n\tMatcherFunction,\n\tMatcherResult,\n\tMatcherWithArgsFunction,\n} from './types';\n\ninterface SpyInfo {\n\tspy: Mock;\n\tpass: boolean;\n\tcalls: unknown[][];\n\tmatcherName: string;\n\tmethodName: string;\n\texpected?: unknown[];\n}\n\nconst createErrorMessage = ( spyInfo: SpyInfo ) => {\n\tconst { spy, pass, calls, matcherName, methodName, expected } = spyInfo;\n\tconst hint = pass ? `.not${ matcherName }` : matcherName;\n\tconst message = pass\n\t\t? `Expected mock function not to be called but it was called with:\\n${ calls.map(\n\t\t\t\tprintReceived\n\t\t ) }`\n\t\t: `Expected mock function to be called${\n\t\t\t\texpected ? ` with:\\n${ printExpected( expected ) }\\n` : '.'\n\t\t }\\nbut it was called with:\\n${ calls.map( printReceived ) }`;\n\n\treturn () =>\n\t\t`${ matcherHint( hint, spy.getMockName() ) }` +\n\t\t'\\n\\n' +\n\t\tmessage +\n\t\t'\\n\\n' +\n\t\t`console.${ methodName }() should not be used unless explicitly expected\\n` +\n\t\t'See https://www.npmjs.com/package/@wordpress/jest-console for details.';\n};\n\nconst createSpyInfo = (\n\tspy: Mock,\n\tmatcherName: string,\n\tmethodName: string,\n\texpected?: unknown[]\n) => {\n\tconst calls = spy.mock.calls;\n\n\tconst pass = expected\n\t\t? JSON.stringify( calls ).includes( JSON.stringify( expected ) )\n\t\t: calls.length > 0;\n\n\tconst message = createErrorMessage( {\n\t\tspy,\n\t\tpass,\n\t\tcalls,\n\t\tmatcherName,\n\t\tmethodName,\n\t\texpected,\n\t} );\n\n\treturn {\n\t\tpass,\n\t\tmessage,\n\t};\n};\n\nconst createToHaveBeenCalledMatcher =\n\t( matcherName: string, methodName: string ) =>\n\t( received: Record< string, Mock > ): MatcherResult => {\n\t\tconst spy = received[ methodName ] as ExtendedMock;\n\t\tconst spyInfo = createSpyInfo( spy, matcherName, methodName );\n\t\tspy.assertionsNumber += 1;\n\t\treturn spyInfo;\n\t};\n\nconst createToHaveBeenCalledWith = (\n\tmatcherName: string,\n\tmethodName: string\n) =>\n\tfunction (\n\t\treceived: Record< string, Mock >,\n\t\t...expected: unknown[]\n\t): MatcherResult {\n\t\tconst spy = received[ methodName ] as ExtendedMock;\n\t\tconst spyInfo = createSpyInfo( spy, matcherName, methodName, expected );\n\t\tspy.assertionsNumber += 1;\n\t\treturn spyInfo;\n\t};\n\ntype MatchersObject = Record<\n\tstring,\n\tMatcherFunction | MatcherWithArgsFunction\n>;\n\nexpect.extend(\n\tObject.entries( supportedMatchers ).reduce< MatchersObject >(\n\t\t( result, [ methodName, matcherName ] ) => {\n\t\t\tconst matcherNameWith = `${ matcherName }With`;\n\n\t\t\treturn {\n\t\t\t\t...result,\n\t\t\t\t[ matcherName ]: createToHaveBeenCalledMatcher(\n\t\t\t\t\t`.${ matcherName }`,\n\t\t\t\t\tmethodName\n\t\t\t\t),\n\t\t\t\t[ matcherNameWith ]: createToHaveBeenCalledWith(\n\t\t\t\t\t`.${ matcherNameWith }`,\n\t\t\t\t\tmethodName\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t{}\n\t)\n);\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,aAAa,eAAe,qBAAqB;AAK1D,OAAO,uBAAuB;AAkB9B,
|
|
5
|
+
"mappings": ";AAGA,SAAS,aAAa,eAAe,qBAAqB;AAK1D,OAAO,uBAAuB;AAkB9B,IAAM,qBAAqB,CAAE,YAAsB;AAClD,QAAM,EAAE,KAAK,MAAM,OAAO,aAAa,YAAY,SAAS,IAAI;AAChE,QAAM,OAAO,OAAO,OAAQ,WAAY,KAAK;AAC7C,QAAM,UAAU,OACb;AAAA,EAAqE,MAAM;AAAA,IAC3E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;AAAA,IACD;AAAA,IACA,CAAC;AAAA,EACF;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/supported-matchers.ts"],
|
|
4
4
|
"sourcesContent": ["const supportedMatchers: Record< string, string > = {\n\terror: 'toHaveErrored',\n\tinfo: 'toHaveInformed',\n\tlog: 'toHaveLogged',\n\twarn: 'toHaveWarned',\n};\n\nexport default supportedMatchers;\n"],
|
|
5
|
-
"mappings": "AAAA,
|
|
5
|
+
"mappings": ";AAAA,IAAM,oBAA8C;AAAA,EACnD,OAAO;AAAA,EACP,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AACP;AAEA,IAAO,6BAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/jest-console",
|
|
3
|
-
"version": "8.34.0",
|
|
3
|
+
"version": "8.34.1-next.2f1c7c01b.0",
|
|
4
4
|
"description": "Custom Jest matchers for the Console object.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "c6ddcdf455bc02567a2c9e03de6862a2061b85e8"
|
|
53
53
|
}
|