UNPKG

5.08 kBSource Map (JSON)View Raw
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,8BA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