UNPKG

cli-testing-library

Version:

Simple and complete CLI testing utilities that encourage good testing practices.

1 lines 2.02 kB
{"version":3,"file":"to-have-errormessage.cjs","sources":["../../../src/matchers/to-have-errormessage.ts"],"sourcesContent":["import { getDefaultNormalizer } from \"../matches\";\nimport { checkCliInstance, getMessage } from \"./utils\";\nimport type { TestInstance } from \"../types\";\n\nexport function toHaveErrorMessage(\n this: any,\n testInstance: TestInstance,\n checkWith?: string | RegExp,\n) {\n checkCliInstance(testInstance, toHaveErrorMessage, this);\n\n const expectsErrorMessage = checkWith !== undefined;\n\n const errormessage = getDefaultNormalizer()(\n testInstance.stderrArr.map((obj) => obj.contents).join(\"\\n\"),\n );\n\n return {\n pass: expectsErrorMessage\n ? checkWith instanceof RegExp\n ? checkWith.test(errormessage)\n : this.equals(errormessage, checkWith)\n : Boolean(testInstance.stderrArr.length),\n message: () => {\n const to = this.isNot ? \"not to\" : \"to\";\n return getMessage(\n this,\n this.utils.matcherHint(\n `${this.isNot ? \".not\" : \"\"}.toHaveErrorMessage`,\n \"instance\",\n \"\",\n ),\n `Expected the instance ${to} have error message`,\n this.utils.printExpected(checkWith),\n \"Received\",\n this.utils.printReceived(errormessage),\n );\n },\n };\n}\n"],"names":["checkCliInstance","getDefaultNormalizer","getMessage"],"mappings":";;;;AAIgB,SAAA,mBAEd,cACA,WACA;AACiBA,yBAAA,cAAc,oBAAoB,IAAI;AAEvD,QAAM,sBAAsB,cAAc;AAE1C,QAAM,eAAeC,QAAAA,qBAAqB;AAAA,IACxC,aAAa,UAAU,IAAI,CAAC,QAAQ,IAAI,QAAQ,EAAE,KAAK,IAAI;AAAA,EAC7D;AAEO,SAAA;AAAA,IACL,MAAM,sBACF,qBAAqB,SACnB,UAAU,KAAK,YAAY,IAC3B,KAAK,OAAO,cAAc,SAAS,IACrC,QAAQ,aAAa,UAAU,MAAM;AAAA,IACzC,SAAS,MAAM;AACP,YAAA,KAAK,KAAK,QAAQ,WAAW;AAC5B,aAAAC,MAAA;AAAA,QACL;AAAA,QACA,KAAK,MAAM;AAAA,UACT,GAAG,KAAK,QAAQ,SAAS,EAAE;AAAA,UAC3B;AAAA,UACA;AAAA,QACF;AAAA,QACA,yBAAyB,EAAE;AAAA,QAC3B,KAAK,MAAM,cAAc,SAAS;AAAA,QAClC;AAAA,QACA,KAAK,MAAM,cAAc,YAAY;AAAA,MACvC;AAAA,IAAA;AAAA,EAEJ;AACF;;"}