UNPKG

console-fail-test

Version:

Gently fails test runs if the console was used during them. 📢

1 lines • 2.08 kB
{"version":3,"sources":["../../src/spies/jasmine.ts"],"sourcesContent":["import { SpyCallArgs, SpyFactory, SpyFactoryGetter } from \"./spyTypes.js\";\n\ndeclare interface Jasmine {\n\tcreateSpy(): Function & any;\n}\n\ndeclare const jasmine: Jasmine | undefined;\n\nconst isJasmineModule = (spyLibrary: unknown): spyLibrary is Jasmine => {\n\treturn (\n\t\ttypeof spyLibrary === \"object\" &&\n\t\ttypeof (spyLibrary as Partial<Jasmine>).createSpy === \"function\"\n\t);\n};\n\nconst createJasmineSpyFactory = (spyLibrary: Jasmine): SpyFactory => {\n\treturn (container: any, methodName: string) => {\n\t\tconst methodCalls: SpyCallArgs[] = [];\n\t\tconst originalMethod = container[methodName];\n\n\t\tcontainer[methodName] = spyLibrary.createSpy().and.callFake(function (\n\t\t\tthis: unknown,\n\t\t\t...args: SpyCallArgs\n\t\t) {\n\t\t\tmethodCalls.push(args);\n\t\t\treturn originalMethod.apply(this, args);\n\t\t});\n\n\t\treturn {\n\t\t\tgetCalls: () => methodCalls,\n\t\t\trestore: () => {\n\t\t\t\tcontainer[methodName] = originalMethod;\n\t\t\t},\n\t\t};\n\t};\n};\n\nexport const selectJasmineSpyFactory: SpyFactoryGetter = ({ spyLibrary }) => {\n\tif (isJasmineModule(spyLibrary)) {\n\t\treturn createJasmineSpyFactory(spyLibrary);\n\t}\n\n\tif (typeof jasmine !== \"undefined\" && isJasmineModule(jasmine)) {\n\t\treturn createJasmineSpyFactory(jasmine);\n\t}\n\n\treturn undefined;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,MAAM,kBAAkB,CAAC,eAA+C;AACvE,SACC,OAAO,eAAe,YACtB,OAAQ,WAAgC,cAAc;AAExD;AAEA,MAAM,0BAA0B,CAAC,eAAoC;AACpE,SAAO,CAAC,WAAgB,eAAuB;AAC9C,UAAM,cAA6B,CAAC;AACpC,UAAM,iBAAiB,UAAU,UAAU;AAE3C,cAAU,UAAU,IAAI,WAAW,UAAU,EAAE,IAAI,SAAS,YAExD,MACF;AACD,kBAAY,KAAK,IAAI;AACrB,aAAO,eAAe,MAAM,MAAM,IAAI;AAAA,IACvC,CAAC;AAED,WAAO;AAAA,MACN,UAAU,MAAM;AAAA,MAChB,SAAS,MAAM;AACd,kBAAU,UAAU,IAAI;AAAA,MACzB;AAAA,IACD;AAAA,EACD;AACD;AAEO,MAAM,0BAA4C,CAAC,EAAE,WAAW,MAAM;AAC5E,MAAI,gBAAgB,UAAU,GAAG;AAChC,WAAO,wBAAwB,UAAU;AAAA,EAC1C;AAEA,MAAI,OAAO,YAAY,eAAe,gBAAgB,OAAO,GAAG;AAC/D,WAAO,wBAAwB,OAAO;AAAA,EACvC;AAEA,SAAO;AACR;","names":[]}