@thisisagile/easy-test
Version:
Straightforward library for testing microservices built with @thisisagile/easy
1 lines • 2.61 kB
Source Map (JSON)
{"version":3,"sources":["../../src/matchers/ResultMatchers.ts"],"sourcesContent":["import { match } from './Match';\nimport { Results } from '../utils/Types';\n\n// Tests for handling Results.\n\nconst notDefined = 'Results is not defined.';\nconst doesNotFail = 'Results does not fail.';\n\nconst hasMessage = (res: Results, message: string) => res.results.some((r: any) => r.message === message);\n\nconst messages = (res: Results): string => \"'\" + res?.results.map(r => r.message).join(\"', '\") + \"'\";\n\nexport const toResultWith = (results: Results, message: string): jest.CustomMatcherResult =>\n match(results)\n .undefined(r => r, notDefined)\n .not(\n r => hasMessage(r, message),\n r => `Results does not have message '${message}', but it has messages ${messages(r)} instead.`\n )\n .else(`Succeeds with message ${message}`);\n\nexport const toFail = (results: Results): jest.CustomMatcherResult =>\n match(results)\n .undefined(r => r, notDefined)\n .not(r => !r.isValid, doesNotFail)\n .else('Results does not fail');\n\nexport const toFailWith = (results: Results, message: string): jest.CustomMatcherResult =>\n match(results)\n .undefined(r => r, notDefined)\n .not(r => !r.isValid, doesNotFail)\n .not(\n r => hasMessage(r, message),\n r => `Fails, but results does not have message '${message}', but it has messages ${messages(r)} instead.`\n )\n .else(`Fails with message '${message}'`);\n\nexpect.extend({\n toResultWith,\n toFail: toFail,\n toFailWith: toFailWith,\n});\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace jest {\n interface Matchers<R, T> {\n toResultWith(message: string): R;\n toFail(): R;\n toFailWith(message: string): R;\n }\n }\n}\n"],"mappings":";;;;;;;AAKA,IAAM,aAAa;AACnB,IAAM,cAAc;AAEpB,IAAM,aAAa,CAAC,KAAc,YAAoB,IAAI,QAAQ,KAAK,CAAC,MAAW,EAAE,YAAY,OAAO;AAExG,IAAM,WAAW,CAAC,QAAyB,MAAM,KAAK,QAAQ,IAAI,OAAK,EAAE,OAAO,EAAE,KAAK,MAAM,IAAI;AAE1F,IAAM,eAAe,CAAC,SAAkB,YAC7C,MAAM,OAAO,EACV,UAAU,OAAK,GAAG,UAAU,EAC5B;AAAA,EACC,OAAK,WAAW,GAAG,OAAO;AAAA,EAC1B,OAAK,kCAAkC,OAAO,0BAA0B,SAAS,CAAC,CAAC;AACrF,EACC,KAAK,yBAAyB,OAAO,EAAE;AAErC,IAAM,SAAS,CAAC,YACrB,MAAM,OAAO,EACV,UAAU,OAAK,GAAG,UAAU,EAC5B,IAAI,OAAK,CAAC,EAAE,SAAS,WAAW,EAChC,KAAK,uBAAuB;AAE1B,IAAM,aAAa,CAAC,SAAkB,YAC3C,MAAM,OAAO,EACV,UAAU,OAAK,GAAG,UAAU,EAC5B,IAAI,OAAK,CAAC,EAAE,SAAS,WAAW,EAChC;AAAA,EACC,OAAK,WAAW,GAAG,OAAO;AAAA,EAC1B,OAAK,6CAA6C,OAAO,0BAA0B,SAAS,CAAC,CAAC;AAChG,EACC,KAAK,uBAAuB,OAAO,GAAG;AAE3C,OAAO,OAAO;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AACF,CAAC;","names":[]}