@thisisagile/easy-test
Version:
Straightforward library for testing microservices built with @thisisagile/easy
1 lines • 2.55 kB
Source Map (JSON)
{"version":3,"sources":["../../src/matchers/toBeRoutedTo.ts"],"sourcesContent":["import { checkDefined } from './Check';\nimport { Uri } from '../utils/Types';\nimport { asString } from '../utils/Utils';\nimport { match } from './Match';\n\nexport const weExpectedButReceivedInstead = ([r, e]: [any, any]) => `We expected ${asString(e)}, but we received '${asString(r)}' instead.`;\n\nexport function toMatchAsString(this: jest.MatcherContext, received: unknown, expected: unknown): jest.CustomMatcherResult {\n return checkDefined(this, received, expected)\n .not(\n ([r, e]) => this.equals(asString(r), asString(e)),\n ([r, e]) => weExpectedButReceivedInstead([r, e])\n )\n .else();\n}\n\n// export function toBeRoutedTo(this: jest.MatcherContext, query: jest.Mock, expected: Uri): jest.CustomMatcherResult {\n// return check<any[]>(this, query?.mock?.calls)\n// .undefined(r => r, \"Uri is unknown.\")\n// .not(r => r.length === 1, \"Method was not called.\")\n// .not(r => this.equals(asString(r[0][0]), asString(expected)), ([r,e]) => weExpectedButReceivedInstead([r[0][0], e]))\n// .else();\n// }\n\nexport const toBeRoutedTo = (query: jest.Mock, expected: Uri): jest.CustomMatcherResult =>\n match<any[]>(query?.mock?.calls)\n .undefined(c => c, 'Uri is unknown.')\n .not(c => c.length === 1, 'Method was not called.')\n .not(\n c => asString(c[0][0]) === asString(expected),\n c => `We expected uri '${asString(expected)}', but we received uri '${asString(c[0][0])}' instead.`\n )\n .else(`Called uri does match '${asString(expected)}'`);\n\nexpect.extend({\n toBeRoutedTo: toBeRoutedTo,\n});\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace jest {\n interface Matchers<R, T> {\n toBeRoutedTo(uri: Uri): R;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AAKO,IAAM,+BAA+B,CAAC,CAAC,GAAG,CAAC,MAAkB,eAAe,SAAS,CAAC,CAAC,sBAAsB,SAAS,CAAC,CAAC;AAExH,SAAS,gBAA2C,UAAmB,UAA6C;AACzH,SAAO,aAAa,MAAM,UAAU,QAAQ,EACzC;AAAA,IACC,CAAC,CAAC,GAAG,CAAC,MAAM,KAAK,OAAO,SAAS,CAAC,GAAG,SAAS,CAAC,CAAC;AAAA,IAChD,CAAC,CAAC,GAAG,CAAC,MAAM,6BAA6B,CAAC,GAAG,CAAC,CAAC;AAAA,EACjD,EACC,KAAK;AACV;AAUO,IAAM,eAAe,CAAC,OAAkB,aAC7C,MAAa,OAAO,MAAM,KAAK,EAC5B,UAAU,OAAK,GAAG,iBAAiB,EACnC,IAAI,OAAK,EAAE,WAAW,GAAG,wBAAwB,EACjD;AAAA,EACC,OAAK,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,SAAS,QAAQ;AAAA,EAC5C,OAAK,oBAAoB,SAAS,QAAQ,CAAC,2BAA2B,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACzF,EACC,KAAK,0BAA0B,SAAS,QAAQ,CAAC,GAAG;AAEzD,OAAO,OAAO;AAAA,EACZ;AACF,CAAC;","names":[]}