@wordpress/jest-console 7.11.1 → 7.13.1-next.5a1d1283.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/matchers.js CHANGED
@@ -11,27 +11,46 @@ var _supportedMatchers = _interopRequireDefault(require("./supported-matchers"))
11
11
  * Internal dependencies
12
12
  */
13
13
 
14
- const createToHaveBeenCalledMatcher = (matcherName, methodName) => received => {
15
- const spy = received[methodName];
14
+ const createErrorMessage = spyInfo => {
15
+ const {
16
+ spy,
17
+ pass,
18
+ calls,
19
+ matcherName,
20
+ methodName,
21
+ expected
22
+ } = spyInfo;
23
+ const hint = pass ? `.not${matcherName}` : matcherName;
24
+ const message = pass ? `Expected mock function not to be called but it was called with:\n${calls.map(_jestMatcherUtils.printReceived)}` : `Expected mock function to be called${expected ? ` with:\n${(0, _jestMatcherUtils.printExpected)(expected)}\n` : '.'}\nbut it was called with:\n${calls.map(_jestMatcherUtils.printReceived)}`;
25
+ return () => `${(0, _jestMatcherUtils.matcherHint)(hint, spy.getMockName())}` + '\n\n' + message + '\n\n' + `console.${methodName}() should not be used unless explicitly expected\n` + 'See https://www.npmjs.com/package/@wordpress/jest-console for details.';
26
+ };
27
+ const createSpyInfo = (spy, matcherName, methodName, expected) => {
16
28
  const calls = spy.mock.calls;
17
- const pass = calls.length > 0;
18
- const message = pass ? () => (0, _jestMatcherUtils.matcherHint)(`.not${matcherName}`, spy.getMockName()) + '\n\n' + 'Expected mock function not to be called but it was called with:\n' + calls.map(_jestMatcherUtils.printReceived) : () => (0, _jestMatcherUtils.matcherHint)(matcherName, spy.getMockName()) + '\n\n' + 'Expected mock function to be called.';
19
- spy.assertionsNumber += 1;
29
+ const pass = expected ? JSON.stringify(calls).includes(JSON.stringify(expected)) : calls.length > 0;
30
+ const message = createErrorMessage({
31
+ spy,
32
+ pass,
33
+ calls,
34
+ matcherName,
35
+ methodName,
36
+ expected
37
+ });
20
38
  return {
21
- message,
22
- pass
39
+ pass,
40
+ message
23
41
  };
24
42
  };
43
+ const createToHaveBeenCalledMatcher = (matcherName, methodName) => received => {
44
+ const spy = received[methodName];
45
+ const spyInfo = createSpyInfo(spy, matcherName, methodName);
46
+ spy.assertionsNumber += 1;
47
+ return spyInfo;
48
+ };
25
49
  const createToHaveBeenCalledWith = (matcherName, methodName) => function (received, ...expected) {
26
50
  const spy = received[methodName];
27
- const calls = spy.mock.calls;
28
- const pass = calls.some(objects => this.equals(objects, expected));
29
- const message = pass ? () => (0, _jestMatcherUtils.matcherHint)(`.not${matcherName}`, spy.getMockName()) + '\n\n' + 'Expected mock function not to be called with:\n' + (0, _jestMatcherUtils.printExpected)(expected) : () => (0, _jestMatcherUtils.matcherHint)(matcherName, spy.getMockName()) + '\n\n' + 'Expected mock function to be called with:\n' + (0, _jestMatcherUtils.printExpected)(expected) + '\n' + 'but it was called with:\n' + calls.map(_jestMatcherUtils.printReceived);
51
+ const spyInfo = createSpyInfo(spy, matcherName, methodName, expected);
30
52
  spy.assertionsNumber += 1;
31
- return {
32
- message,
33
- pass
34
- };
53
+ return spyInfo;
35
54
  };
36
55
  expect.extend(Object.entries(_supportedMatchers.default).reduce((result, [methodName, matcherName]) => {
37
56
  const matcherNameWith = `${matcherName}With`;
@@ -1 +1 @@
1
- {"version":3,"names":["_jestMatcherUtils","require","_supportedMatchers","_interopRequireDefault","createToHaveBeenCalledMatcher","matcherName","methodName","received","spy","calls","mock","pass","length","message","matcherHint","getMockName","map","printReceived","assertionsNumber","createToHaveBeenCalledWith","expected","some","objects","equals","printExpected","expect","extend","Object","entries","supportedMatchers","reduce","result","matcherNameWith"],"sources":["@wordpress/jest-console/src/matchers.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { matcherHint, printExpected, printReceived } from 'jest-matcher-utils';\n\n/**\n * Internal dependencies\n */\nimport supportedMatchers from './supported-matchers';\n\nconst createToHaveBeenCalledMatcher =\n\t( matcherName, methodName ) => ( received ) => {\n\t\tconst spy = received[ methodName ];\n\t\tconst calls = spy.mock.calls;\n\t\tconst pass = calls.length > 0;\n\t\tconst message = pass\n\t\t\t? () =>\n\t\t\t\t\tmatcherHint( `.not${ matcherName }`, spy.getMockName() ) +\n\t\t\t\t\t'\\n\\n' +\n\t\t\t\t\t'Expected mock function not to be called but it was called with:\\n' +\n\t\t\t\t\tcalls.map( printReceived )\n\t\t\t: () =>\n\t\t\t\t\tmatcherHint( matcherName, spy.getMockName() ) +\n\t\t\t\t\t'\\n\\n' +\n\t\t\t\t\t'Expected mock function to be called.';\n\n\t\tspy.assertionsNumber += 1;\n\n\t\treturn {\n\t\t\tmessage,\n\t\t\tpass,\n\t\t};\n\t};\n\nconst createToHaveBeenCalledWith = ( matcherName, methodName ) =>\n\tfunction ( received, ...expected ) {\n\t\tconst spy = received[ methodName ];\n\t\tconst calls = spy.mock.calls;\n\t\tconst pass = calls.some( ( objects ) =>\n\t\t\tthis.equals( objects, expected )\n\t\t);\n\t\tconst message = pass\n\t\t\t? () =>\n\t\t\t\t\tmatcherHint( `.not${ matcherName }`, spy.getMockName() ) +\n\t\t\t\t\t'\\n\\n' +\n\t\t\t\t\t'Expected mock function not to be called with:\\n' +\n\t\t\t\t\tprintExpected( expected )\n\t\t\t: () =>\n\t\t\t\t\tmatcherHint( matcherName, spy.getMockName() ) +\n\t\t\t\t\t'\\n\\n' +\n\t\t\t\t\t'Expected mock function to be called with:\\n' +\n\t\t\t\t\tprintExpected( expected ) +\n\t\t\t\t\t'\\n' +\n\t\t\t\t\t'but it was called with:\\n' +\n\t\t\t\t\tcalls.map( printReceived );\n\n\t\tspy.assertionsNumber += 1;\n\n\t\treturn {\n\t\t\tmessage,\n\t\t\tpass,\n\t\t};\n\t};\n\nexpect.extend(\n\tObject.entries( supportedMatchers ).reduce(\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\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CAAIC,OAAO,IACjC,IAAI,CAACC,MAAM,CAAED,OAAO,EAAEF,QAAS,CAChC,CAAC;EACD,MAAMP,OAAO,GAAGF,IAAI,GACjB,MACA,IAAAG,6BAAW,EAAG,OAAOT,WAAa,EAAC,EAAEG,GAAG,CAACO,WAAW,CAAC,CAAE,CAAC,GACxD,MAAM,GACN,iDAAiD,GACjD,IAAAS,+BAAa,EAAEJ,QAAS,CAAC,GACzB,MACA,IAAAN,6BAAW,EAAET,WAAW,EAAEG,GAAG,CAACO,WAAW,CAAC,CAAE,CAAC,GAC7C,MAAM,GACN,6CAA6C,GAC7C,IAAAS,+BAAa,EAAEJ,QAAS,CAAC,GACzB,IAAI,GACJ,2BAA2B,GAC3BX,KAAK,CAACO,GAAG,CAAEC,+BAAc,CAAC;EAE7BT,GAAG,CAACU,gBAAgB,IAAI,CAAC;EAEzB,OAAO;IACNL,OAAO;IACPF;EACD,CAAC;AACF,CAAC;AAEFc,MAAM,CAACC,MAAM,CACZC,MAAM,CAACC,OAAO,CAAEC,0BAAkB,CAAC,CAACC,MAAM,CACzC,CAAEC,MAAM,EAAE,CAAEzB,UAAU,EAAED,WAAW,CAAE,KAAM;EAC1C,MAAM2B,eAAe,GAAI,GAAG3B,WAAa,MAAK;EAE9C,OAAO;IACN,GAAG0B,MAAM;IACT,CAAE1B,WAAW,GAAID,6BAA6B,CAC5C,IAAIC,WAAa,EAAC,EACnBC,UACD,CAAC;IACD,CAAE0B,eAAe,GAAIb,0BAA0B,CAC7C,IAAIa,eAAiB,EAAC,EACvB1B,UACD;EACD,CAAC;AACF,CAAC,EACD,CAAC,CACF,CACD,CAAC"}
1
+ {"version":3,"names":["_jestMatcherUtils","require","_supportedMatchers","_interopRequireDefault","createErrorMessage","spyInfo","spy","pass","calls","matcherName","methodName","expected","hint","message","map","printReceived","printExpected","matcherHint","getMockName","createSpyInfo","mock","JSON","stringify","includes","length","createToHaveBeenCalledMatcher","received","assertionsNumber","createToHaveBeenCalledWith","expect","extend","Object","entries","supportedMatchers","reduce","result","matcherNameWith"],"sources":["@wordpress/jest-console/src/matchers.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { matcherHint, printExpected, printReceived } from 'jest-matcher-utils';\n\n/**\n * Internal dependencies\n */\nimport supportedMatchers from './supported-matchers';\n\nconst createErrorMessage = ( 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 = ( spy, matcherName, methodName, expected ) => {\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, methodName ) => ( received ) => {\n\t\tconst spy = received[ methodName ];\n\t\tconst spyInfo = createSpyInfo( spy, matcherName, methodName );\n\n\t\tspy.assertionsNumber += 1;\n\n\t\treturn spyInfo;\n\t};\n\nconst createToHaveBeenCalledWith = ( matcherName, methodName ) =>\n\tfunction ( received, ...expected ) {\n\t\tconst spy = received[ methodName ];\n\t\tconst spyInfo = createSpyInfo( spy, matcherName, methodName, expected );\n\n\t\tspy.assertionsNumber += 1;\n\n\t\treturn spyInfo;\n\t};\n\nexpect.extend(\n\tObject.entries( supportedMatchers ).reduce(\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"],"mappings":";;;AAGA,IAAAA,iBAAA,GAAAC,OAAA;AAKA,IAAAC,kBAAA,GAAAC,sBAAA,CAAAF,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA,MAAMG,kBAAkB,GAAKC,OAAO,IAAM;EACzC,MAAM;IAAEC,GAAG;IAAEC,IAAI;IAAEC,KAAK;IAAEC,WAAW;IAAEC,UAAU;IAAEC;EAAS,CAAC,GAAGN,OAAO;EACvE,MAAMO,IAAI,GAAGL,IAAI,GAAI,OAAOE,WAAa,EAAC,GAAGA,WAAW;EACxD,MAAMI,OAAO,GAAGN,IAAI,GAChB,oEAAoEC,KAAK,CAACM,GAAG,CAC9EC,+BACA,CAAG,EAAC,GACH,sCACDJ,QAAQ,GAAI,WAAW,IAAAK,+BAAa,EAAEL,QAAS,CAAG,IAAG,GAAG,GACvD,8BAA8BH,KAAK,CAACM,GAAG,CAAEC,+BAAc,CAAG,EAAC;EAE/D,OAAO,MACL,GAAG,IAAAE,6BAAW,EAAEL,IAAI,EAAEN,GAAG,CAACY,WAAW,CAAC,CAAE,CAAG,EAAC,GAC7C,MAAM,GACNL,OAAO,GACP,MAAM,GACL,WAAWH,UAAY,oDAAmD,GAC3E,wEAAwE;AAC1E,CAAC;AA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B,UAAU,EAAED,WAAW,CAAE,KAAM;EAC1C,MAAM2B,eAAe,GAAI,GAAG3B,WAAa,MAAK;EAE9C,OAAO;IACN,GAAG0B,MAAM;IACT,CAAE1B,WAAW,GAAIgB,6BAA6B,CAC5C,IAAIhB,WAAa,EAAC,EACnBC,UACD,CAAC;IACD,CAAE0B,eAAe,GAAIR,0BAA0B,CAC7C,IAAIQ,eAAiB,EAAC,EACvB1B,UACD;EACD,CAAC;AACF,CAAC,EACD,CAAC,CACF,CACD,CAAC"}
@@ -7,27 +7,46 @@ import { matcherHint, printExpected, printReceived } from 'jest-matcher-utils';
7
7
  * Internal dependencies
8
8
  */
9
9
  import supportedMatchers from './supported-matchers';
10
- const createToHaveBeenCalledMatcher = (matcherName, methodName) => received => {
11
- const spy = received[methodName];
10
+ const createErrorMessage = spyInfo => {
11
+ const {
12
+ spy,
13
+ pass,
14
+ calls,
15
+ matcherName,
16
+ methodName,
17
+ expected
18
+ } = spyInfo;
19
+ const hint = pass ? `.not${matcherName}` : matcherName;
20
+ const message = pass ? `Expected mock function not to be called but it was called with:\n${calls.map(printReceived)}` : `Expected mock function to be called${expected ? ` with:\n${printExpected(expected)}\n` : '.'}\nbut it was called with:\n${calls.map(printReceived)}`;
21
+ return () => `${matcherHint(hint, spy.getMockName())}` + '\n\n' + message + '\n\n' + `console.${methodName}() should not be used unless explicitly expected\n` + 'See https://www.npmjs.com/package/@wordpress/jest-console for details.';
22
+ };
23
+ const createSpyInfo = (spy, matcherName, methodName, expected) => {
12
24
  const calls = spy.mock.calls;
13
- const pass = calls.length > 0;
14
- const message = pass ? () => matcherHint(`.not${matcherName}`, spy.getMockName()) + '\n\n' + 'Expected mock function not to be called but it was called with:\n' + calls.map(printReceived) : () => matcherHint(matcherName, spy.getMockName()) + '\n\n' + 'Expected mock function to be called.';
15
- spy.assertionsNumber += 1;
25
+ const pass = expected ? JSON.stringify(calls).includes(JSON.stringify(expected)) : calls.length > 0;
26
+ const message = createErrorMessage({
27
+ spy,
28
+ pass,
29
+ calls,
30
+ matcherName,
31
+ methodName,
32
+ expected
33
+ });
16
34
  return {
17
- message,
18
- pass
35
+ pass,
36
+ message
19
37
  };
20
38
  };
39
+ const createToHaveBeenCalledMatcher = (matcherName, methodName) => received => {
40
+ const spy = received[methodName];
41
+ const spyInfo = createSpyInfo(spy, matcherName, methodName);
42
+ spy.assertionsNumber += 1;
43
+ return spyInfo;
44
+ };
21
45
  const createToHaveBeenCalledWith = (matcherName, methodName) => function (received, ...expected) {
22
46
  const spy = received[methodName];
23
- const calls = spy.mock.calls;
24
- const pass = calls.some(objects => this.equals(objects, expected));
25
- const message = pass ? () => matcherHint(`.not${matcherName}`, spy.getMockName()) + '\n\n' + 'Expected mock function not to be called with:\n' + printExpected(expected) : () => matcherHint(matcherName, spy.getMockName()) + '\n\n' + 'Expected mock function to be called with:\n' + printExpected(expected) + '\n' + 'but it was called with:\n' + calls.map(printReceived);
47
+ const spyInfo = createSpyInfo(spy, matcherName, methodName, expected);
26
48
  spy.assertionsNumber += 1;
27
- return {
28
- message,
29
- pass
30
- };
49
+ return spyInfo;
31
50
  };
32
51
  expect.extend(Object.entries(supportedMatchers).reduce((result, [methodName, matcherName]) => {
33
52
  const matcherNameWith = `${matcherName}With`;
@@ -1 +1 @@
1
- {"version":3,"names":["matcherHint","printExpected","printReceived","supportedMatchers","createToHaveBeenCalledMatcher","matcherName","methodName","received","spy","calls","mock","pass","length","message","getMockName","map","assertionsNumber","createToHaveBeenCalledWith","expected","some","objects","equals","expect","extend","Object","entries","reduce","result","matcherNameWith"],"sources":["@wordpress/jest-console/src/matchers.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { matcherHint, printExpected, printReceived } from 'jest-matcher-utils';\n\n/**\n * Internal dependencies\n */\nimport supportedMatchers from './supported-matchers';\n\nconst createToHaveBeenCalledMatcher =\n\t( matcherName, methodName ) => ( received ) => {\n\t\tconst spy = received[ methodName ];\n\t\tconst calls = spy.mock.calls;\n\t\tconst pass = calls.length > 0;\n\t\tconst message = pass\n\t\t\t? () =>\n\t\t\t\t\tmatcherHint( `.not${ matcherName }`, spy.getMockName() ) +\n\t\t\t\t\t'\\n\\n' +\n\t\t\t\t\t'Expected mock function not to be called but it was called with:\\n' +\n\t\t\t\t\tcalls.map( printReceived )\n\t\t\t: () =>\n\t\t\t\t\tmatcherHint( matcherName, spy.getMockName() ) +\n\t\t\t\t\t'\\n\\n' +\n\t\t\t\t\t'Expected mock function to be called.';\n\n\t\tspy.assertionsNumber += 1;\n\n\t\treturn {\n\t\t\tmessage,\n\t\t\tpass,\n\t\t};\n\t};\n\nconst createToHaveBeenCalledWith = ( matcherName, methodName ) =>\n\tfunction ( received, ...expected ) {\n\t\tconst spy = received[ methodName ];\n\t\tconst calls = spy.mock.calls;\n\t\tconst pass = calls.some( ( objects ) =>\n\t\t\tthis.equals( objects, expected )\n\t\t);\n\t\tconst message = pass\n\t\t\t? () =>\n\t\t\t\t\tmatcherHint( `.not${ matcherName }`, spy.getMockName() ) +\n\t\t\t\t\t'\\n\\n' +\n\t\t\t\t\t'Expected mock function not to be called with:\\n' +\n\t\t\t\t\tprintExpected( expected )\n\t\t\t: () =>\n\t\t\t\t\tmatcherHint( matcherName, spy.getMockName() ) +\n\t\t\t\t\t'\\n\\n' +\n\t\t\t\t\t'Expected mock function to be called with:\\n' +\n\t\t\t\t\tprintExpected( expected ) +\n\t\t\t\t\t'\\n' +\n\t\t\t\t\t'but it was called with:\\n' +\n\t\t\t\t\tcalls.map( printReceived );\n\n\t\tspy.assertionsNumber += 1;\n\n\t\treturn {\n\t\t\tmessage,\n\t\t\tpass,\n\t\t};\n\t};\n\nexpect.extend(\n\tObject.entries( supportedMatchers ).reduce(\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\tmeth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OAAO,EAAEF,QAAS,CAChC,CAAC;EACD,MAAML,OAAO,GAAGF,IAAI,GACjB,MACAX,WAAW,CAAG,OAAOK,WAAa,EAAC,EAAEG,GAAG,CAACM,WAAW,CAAC,CAAE,CAAC,GACxD,MAAM,GACN,iDAAiD,GACjDb,aAAa,CAAEiB,QAAS,CAAC,GACzB,MACAlB,WAAW,CAAEK,WAAW,EAAEG,GAAG,CAACM,WAAW,CAAC,CAAE,CAAC,GAC7C,MAAM,GACN,6CAA6C,GAC7Cb,aAAa,CAAEiB,QAAS,CAAC,GACzB,IAAI,GACJ,2BAA2B,GAC3BT,KAAK,CAACM,GAAG,CAAEb,aAAc,CAAC;EAE7BM,GAAG,CAACQ,gBAAgB,IAAI,CAAC;EAEzB,OAAO;IACNH,OAAO;IACPF;EACD,CAAC;AACF,CAAC;AAEFW,MAAM,CAACC,MAAM,CACZC,MAAM,CAACC,OAAO,CAAEtB,iBAAkB,CAAC,CAACuB,MAAM,CACzC,CAAEC,MAAM,EAAE,CAAErB,UAAU,EAAED,WAAW,CAAE,KAAM;EAC1C,MAAMuB,eAAe,GAAI,GAAGvB,WAAa,MAAK;EAE9C,OAAO;IACN,GAAGsB,MAAM;IACT,CAAEtB,WAAW,GAAID,6BAA6B,CAC5C,IAAIC,WAAa,EAAC,EACnBC,UACD,CAAC;IACD,CAAEsB,eAAe,GAAIX,0BAA0B,CAC7C,IAAIW,eAAiB,EAAC,EACvBtB,UACD;EACD,CAAC;AACF,CAAC,EACD,CAAC,CACF,CACD,CAAC"}
1
+ {"version":3,"names":["matcherHint","printExpected","printReceived","supportedMatchers","createErrorMessage","spyInfo","spy","pass","calls","matcherName","methodName","expected","hint","message","map","getMockName","createSpyInfo","mock","JSON","stringify","includes","length","createToHaveBeenCalledMatcher","received","assertionsNumber","createToHaveBeenCalledWith","expect","extend","Object","entries","reduce","result","matcherNameWith"],"sources":["@wordpress/jest-console/src/matchers.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { matcherHint, printExpected, printReceived } from 'jest-matcher-utils';\n\n/**\n * Internal dependencies\n */\nimport supportedMatchers from './supported-matchers';\n\nconst createErrorMessage = ( 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 = ( spy, matcherName, methodName, expected ) => {\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, methodName ) => ( received ) => {\n\t\tconst spy = received[ methodName ];\n\t\tconst spyInfo = createSpyInfo( spy, matcherName, methodName );\n\n\t\tspy.assertionsNumber += 1;\n\n\t\treturn spyInfo;\n\t};\n\nconst createToHaveBeenCalledWith = ( matcherName, methodName ) =>\n\tfunction ( received, ...expected ) {\n\t\tconst spy = received[ methodName ];\n\t\tconst spyInfo = createSpyInfo( spy, matcherName, methodName, expected );\n\n\t\tspy.assertionsNumber += 1;\n\n\t\treturn spyInfo;\n\t};\n\nexpect.extend(\n\tObject.entries( supportedMatchers ).reduce(\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"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,aAAa,EAAEC,aAAa,QAAQ,oBAAoB;;AAE9E;AACA;AACA;AACA,OAAOC,iBAAiB,MAAM,sBAAsB;AAEpD,MAAMC,kBAAkB,GAAKC,OAAO,IAAM;EACzC,MAAM;IAAEC,GAAG;IAAEC,IAAI;IAAEC,KAAK;IAAEC,WAAW;IAAEC,UAAU;IAAEC;EAAS,CAAC,GAAGN,OAAO;EACvE,MAAMO,IAAI,GAAGL,IAAI,GAAI,OAAOE,WAAa,EAAC,GAAGA,WAAW;EACxD,MAAMI,OAAO,GAAGN,IAAI,GAChB,oEAAoEC,KAAK,CAACM,GAAG,CAC9EZ,aACA,CAAG,EAAC,GACH,sCACDS,QAAQ,GAAI,WAAWV,aAAa,CAAEU,QAAS,CAAG,IAAG,GAAG,GACvD,8BAA8BH,KAAK,CAACM,GAAG,CAAEZ,aAAc,CAAG,EAAC;EAE/D,OAAO,MACL,GAAGF,WAAW,CAAEY,IAAI,EAAEN,GAAG,CAACS,WAAW,CAAC,CAAE,CAAG,EAAC,GAC7C,MAAM,GACNF,OAAO,GACP,MAAM,GACL,WAAWH,UAAY,oDAAmD,GAC3E,wEAAwE;AAC1E,CAAC;AAED,MAAMM,aAAa,GAAGA,CAAEV,GAAG,EAAEG,WAAW,EAAEC,UAAU,EAAEC,QAAQ,KAAM;EACnE,MAAMH,KAAK,GAAGF,G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,CAAEtB,WAAW,GAAIa,6BAA6B,CAC5C,IAAIb,WAAa,EAAC,EACnBC,UACD,CAAC;IACD,CAAEsB,eAAe,GAAIP,0BAA0B,CAC7C,IAAIO,eAAiB,EAAC,EACvBtB,UACD;EACD,CAAC;AACF,CAAC,EACD,CAAC,CACF,CACD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/jest-console",
3
- "version": "7.11.1",
3
+ "version": "7.13.1-next.5a1d1283.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",
@@ -41,5 +41,5 @@
41
41
  "publishConfig": {
42
42
  "access": "public"
43
43
  },
44
- "gitHead": "bb1fbf87bb0f451744530fc6a85de2dff1263bed"
44
+ "gitHead": "fa0b66987dab5a15f38663e06036d09bccffaa4b"
45
45
  }