UNPKG

6.48 kBSource Map (JSON)View Raw
1{"version":3,"file":"async.js","sourceRoot":"","sources":["../../../../modules/@angular/core/testing/async.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,IAAM,OAAO,GAAQ,CAAC,OAAO,MAAM,KAAK,WAAW,GAAG,MAAM,GAAG,MAAM,CAAC,CAAC;AAEvE;;;;;;;;;;;;;;;;GAgBG;AACH,sBAAsB,EAAY;IAChC,8EAA8E;IAC9E,mDAAmD;IACnD,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QACpB,MAAM,CAAC,UAAC,IAAS;YACf,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;gBACV,qFAAqF;gBACrF,gCAAgC;gBAChC,IAAI,GAAG,cAAY,CAAC,CAAC;gBACrB,IAAI,CAAC,IAAI,GAAG,UAAS,CAAM,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC5C,CAAC;YACD,aAAa,CAAC,EAAE,EAAE,IAAI,EAAE,UAAC,GAAQ;gBAC/B,EAAE,CAAC,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC;oBAC5B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,CAAS,GAAG,CAAC,CAAC,CAAC;gBAC3C,CAAC;gBAAC,IAAI,CAAC,CAAC;oBACN,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACjB,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;IACD,4EAA4E;IAC5E,2EAA2E;IAC3E,gEAAgE;IAChE,MAAM,CAAC,cAAM,OAAA,IAAI,OAAO,CAAO,UAAC,cAAc,EAAE,YAAY;QACnD,aAAa,CAAC,EAAE,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;IAClD,CAAC,CAAC,EAFI,CAEJ,CAAC;AACZ,CAAC;AAED,uBAAuB,EAAY,EAAE,cAAwB,EAAE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,CAAC,gBAAgB,CAAC,CAAC;gBAC9C,CAAC;gBACD,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC,CAAC,CAAC;QACL,CAAC,EACD,MAAM,CAAC,CAAC;QACZ,aAAa,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;AACrC,CAAC","sourcesContent":["/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\ndeclare var global: any;\n\nconst _global = <any>(typeof window === 'undefined' ? global : window);\n\n/**\n * Wraps a test function in an asynchronous test zone. The test will automatically\n * complete when all asynchronous calls within this zone are done. Can be used\n * to wrap an {@link inject} call.\n *\n * Example:\n *\n * ```\n * it('...', async(inject([AClass], (object) => {\n * object.doSomething.then(() => {\n * expect(...);\n * })\n * });\n * ```\n *\n * @stable\n */\nexport function async(fn: Function): (done: any) => any {\n // If we're running using the Jasmine test framework, adapt to call the 'done'\n // function when asynchronous activity is finished.\n if (_global.jasmine) {\n return (done: any) => {\n if (!done) {\n // if we run beforeEach in @angular/core/testing/testing_internal then we get no done\n // fake it here and assume sync.\n done = function() {};\n done.fail = function(e: any) { throw e; };\n }\n runInTestZone(fn, done, (err: any) => {\n if (typeof err === 'string') {\n return done.fail(new Error(<string>err));\n } else {\n done.fail(err);\n }\n });\n };\n }\n // Otherwise, return a promise which will resolve when asynchronous activity\n // is finished. This will be correctly consumed by the Mocha framework with\n // it('...', async(myFn)); or can be used in a custom framework.\n return () => new Promise<void>((finishCallback, failCallback) => {\n runInTestZone(fn, finishCallback, failCallback);\n });\n}\n\nfunction runInTestZone(fn: Function, finishCallback: Function, failCallback: Function) {\n const currentZone = Zone.current;\n const AsyncTestZoneSpec = (Zone as any)['AsyncTestZoneSpec'];\n if (AsyncTestZoneSpec === undefined) {\n throw new Error(\n 'AsyncTestZoneSpec is needed for the async() test helper but could not be found. ' +\n 'Please make sure that your environment includes zone.js/dist/async-test.js');\n }\n const ProxyZoneSpec = (Zone as any)['ProxyZoneSpec'] as {\n get(): {setDelegate(spec: ZoneSpec): void; getDelegate(): ZoneSpec;};\n assertPresent: () => void;\n };\n if (ProxyZoneSpec === undefined) {\n throw new Error(\n 'ProxyZoneSpec is needed for the async() test helper but could not be found. ' +\n 'Please make sure that your environment includes zone.js/dist/proxy.js');\n }\n const proxyZoneSpec = ProxyZoneSpec.get();\n ProxyZoneSpec.assertPresent();\n // We need to create the AsyncTestZoneSpec outside the ProxyZone.\n // If we do it in ProxyZone then we will get to infinite recursion.\n const proxyZone = Zone.current.getZoneWith('ProxyZoneSpec');\n const previousDelegate = proxyZoneSpec.getDelegate();\n proxyZone.parent.run(() => {\n const testZoneSpec: ZoneSpec = new AsyncTestZoneSpec(\n () => {\n // Need to restore the original zone.\n currentZone.run(() => {\n if (proxyZoneSpec.getDelegate() == testZoneSpec) {\n // Only reset the zone spec if it's sill this one. Otherwise, assume it's OK.\n proxyZoneSpec.setDelegate(previousDelegate);\n }\n finishCallback();\n });\n },\n (error: any) => {\n // Need to restore the original zone.\n currentZone.run(() => {\n if (proxyZoneSpec.getDelegate() == testZoneSpec) {\n // Only reset the zone spec if it's sill this one. Otherwise, assume it's OK.\n proxyZoneSpec.setDelegate(previousDelegate);\n }\n failCallback(error);\n });\n },\n 'test');\n proxyZoneSpec.setDelegate(testZoneSpec);\n });\n return Zone.current.runGuarded(fn);\n}\n\ninterface DecoratorInvocation {\n type: Function;\n args?: any[];\n}\n"]}
\No newline at end of file