@orchestrator/ngx-testing
Version:
Testing utilities for Angular projects
16 lines (14 loc) • 14 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/common"),require("@angular/core"),require("@angular/core/testing"),require("@angular/platform-browser")):"function"==typeof define&&define.amd?define("@orchestrator/ngx-testing",["exports","@angular/common","@angular/core","@angular/core/testing","@angular/platform-browser"],t):t(((e=e||self).ngx=e.ngx||{},e.ngx.testing={}),e.ng.common,e.ng.core,e.ng.core.testing,e.ng.platformBrowser)}(this,(function(e,t,n,o,r){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */var i=function(e,t){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function u(e,t){function n(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var c,s=function(){return(s=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};function p(e,t,n,o){var r,i=arguments.length,u=i<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(e,t,n,o);else for(var c=e.length-1;c>=0;c--)(r=e[c])&&(u=(i<3?r(u):i>3?r(t,n,u):r(t,n))||u);return i>3&&u&&Object.defineProperty(t,n,u),u}function a(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function f(e,t,n,o){return new(n||(n=Promise))((function(r,i){function u(e){try{s(o.next(e))}catch(e){i(e)}}function c(e){try{s(o.throw(e))}catch(e){i(e)}}function s(e){e.done?r(e.value):new n((function(t){t(e.value)})).then(u,c)}s((o=o.apply(e,t||[])).next())}))}function l(e,t){var n,o,r,i,u={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,o=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(r=(r=u.trys).length>0&&r[r.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){u.label=i[1];break}if(6===i[0]&&u.label<r[1]){u.label=r[1],r=i;break}if(r&&u.label<r[2]){u.label=r[2],u.ops.push(i);break}r[2]&&u.ops.pop(),u.trys.pop();continue}i=t.call(e,u)}catch(e){i=[6,e],o=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function m(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,r,i=n.call(e),u=[];try{for(;(void 0===t||t-- >0)&&!(o=i.next()).done;)u.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return u}function h(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(m(arguments[t]));return e}(c=e.TestTypeKind||(e.TestTypeKind={}))[c.Component=0]="Component",c[c.Directive=1]="Directive";var d=function(){return function(){return null}},y=d;function g(){return d}var v=new n.InjectionToken("TestModuleToken"),C=new n.InjectionToken("TestTypeToken"),b=new n.InjectionToken("TestTypeKindToken"),j=new n.InjectionToken("ExtraConfigToken");function T(e){return Object.keys(e).map((function(t){return{propName:t,templateName:e[t].bindingPropertyName||t}}))}function x(e,t){return Object.keys(e).reduce((function(n,o){var r,i=e[o].find((function(e){return e.ngMetadataName===t}));return i?s(s({},n),((r={})[o]=i,r)):n}),{})}function I(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return e.reduce((function(e,t){return h(e,w(t))}),[])}function w(e){return e||[]}var O=function(){function o(){}return o.forComponent=function(t,n){void 0===n&&(n={});var o=M(t,t,n.ngModule);return{ngModule:o,providers:[{provide:v,useValue:o},{provide:C,useValue:t},{provide:b,useValue:e.TestTypeKind.Component},{provide:j,useValue:n}]}},o.forDirective=function(t,n){void 0===n&&(n={});var o=M(t,n.hostComponent,n.ngModule);return{ngModule:o,providers:[{provide:v,useValue:o},{provide:C,useValue:t},{provide:b,useValue:e.TestTypeKind.Directive},{provide:j,useValue:n}]}},o=p([n.NgModule({imports:[t.CommonModule],exports:[t.CommonModule]})],o)}();function M(e,t,o){return void 0===o&&(o={}),function(){function r(){}return r=p([n.NgModule({imports:I(o.imports,[O]),exports:I(o.exports,[O,e]),declarations:I(o.declarations,[e]),entryComponents:t?I(o.entryComponents,[t]):o.entryComponents,schemas:o.schemas})],r)}()}function _(e,t,n,o){return void 0===n&&(n=""),"<"+e+" "+t.inputs.map((function(e){return"["+e.templateName+']="'+e.propName+'"'})).join(" ")+" "+t.outputs.map((function(e){return"("+e.templateName+')="'+e.propName+'($event)"'})).join(" ")+" "+(o?"string"==typeof o?"let-"+o:Object.keys(o).map((function(e){return"let-"+e+(o[e]?'="'+o[e]+'"':"")})).join(" "):"")+">"+n+"</"+e+">"}function k(e,t,n,o,r){return void 0===o&&(o=""),"<"+t+" "+function(e,t,n){var o=t.filter((function(t){return t.templateName!==e})).map((function(t){var n=t.templateName,o=t.propName;return n.replace(e,"")+": "+o})).join("; "),r=n?"string"==typeof n?"let "+n:Object.keys(n).map((function(e){return"let "+e+(n[e]?": "+n[e]:"")})).join(", "):"";return"*"+e+'="'+e+"; "+o+"; "+r+'"'}(e,n.inputs,r)+">"+o+"</"+t+">"}var N,F,P=function(){function t(e,t){this.cfr=e,this.injector=t,this.testModule=this.injector.get(v),this.typeToken=this.injector.get(C),this.typeKind=this.injector.get(b),this.extraConfig=this.injector.get(j)}return t.prototype.generateModuleFor=function(e){var t=this.testModule,o=this.extraConfig.ngModule;return function(){function r(){}return r=p([n.NgModule({imports:[t],declarations:[e],exports:[e],entryComponents:[e],schemas:o?o.schemas:[]})],r)}()},t.prototype.generate=function(){switch(this.typeKind){case e.TestTypeKind.Component:return this.generateForComponent();case e.TestTypeKind.Directive:return this.generateForDirective();default:throw Error("HostGeneratorService: Cannot generate host component for unknown kind: "+this.typeKind)}},t.prototype.generateForComponent=function(){return this.genForComponent(this.typeToken)},t.prototype.generateForDirective=function(){return this.genForDirective(this.typeToken)},t.prototype.genForComponent=function(e){var t=this.cfr.resolveComponentFactory(e),n="host-"+t.selector,o=this.extraConfig.template||_(t.selector,t,this.extraConfig.projectContent);return this.genComponent({selector:n,template:o},e,t)},t.prototype.genForDirective=function(e){var t=function(e){var t=e.__prop__metadata__,n=x(t,"Input"),o=x(t,"Output");return{inputs:T(n),outputs:T(o)}}(e),n=this.extraConfig.template?"":this.extraConfig.hostComponent?this.cfr.resolveComponentFactory(this.extraConfig.hostComponent).selector:this.extraConfig.hostTag,o=this.extraConfig.template||(n?this.genDirectiveTemplate(n,t):"");return this.genComponent({selector:"host-directive",template:o},e,t)},t.prototype.genDirectiveTemplate=function(e,t){return this.extraConfig.useStarSyntax?k(t.inputs[0].templateName,e,t,this.extraConfig.projectContent,this.extraConfig.templateBindings):_(e,t,this.extraConfig.projectContent,this.extraConfig.templateBindings)},t.prototype.genComponent=function(e,t,o){var r=this;return function(){function i(){r.initComponent(t,this,o)}return p([n.ViewChild(t),a("design:type",Object)],i.prototype,"instance",void 0),i=p([n.Component(e),a("design:paramtypes",[])],i)}()},t.prototype.initComponent=function(e,t,n){n.inputs.forEach((function(e){var n=e.propName;return t[n]=void 0})),n.outputs.forEach((function(n){var o=n.propName;return t[o]=g()(o,e.name,e,(function(){return t.instance}))}))},t.ctorParameters=function(){return[{type:n.ComponentFactoryResolver},{type:n.Injector}]},t.ɵprov=n["ɵɵdefineInjectable"]({factory:function(){return new t(n["ɵɵinject"](n.ComponentFactoryResolver),n["ɵɵinject"](n.INJECTOR))},token:t,providedIn:"root"}),t=p([n.Injectable({providedIn:"root"}),a("design:paramtypes",[n.ComponentFactoryResolver,n.Injector])],t)}(),E=function(){function e(e){this.injector=e,this.hostGeneratorService=this.injector.get(P),this.componentType=this.injector.get(C),this.hostComponentType=this.hostGeneratorService.generate(),this.compiler=this.injector.get(n.Compiler),this._didCompilation=!1}return Object.defineProperty(e.prototype,"fixture",{get:function(){return this._fixture},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"hostElement",{get:function(){return this._fixture.debugElement},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"hostHtmlElement",{get:function(){return this._fixture.nativeElement},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"hostComponent",{get:function(){return this._fixture.componentInstance},enumerable:!0,configurable:!0}),e.prototype.ngOnDestroy=function(){if(this._fixture)try{this._fixture.destroy()}catch(e){}},e.prototype.compileComponents=function(){return f(this,void 0,void 0,(function(){var e;return l(this,(function(t){switch(t.label){case 0:return this._didCompilation?[3,3]:(this._didCompilation=!0,e=this.hostGeneratorService.generateModuleFor(this.hostComponentType),[4,this.compiler.compileModuleAndAllComponentsAsync(e)]);case 1:return t.sent(),[4,o.TestBed.compileComponents()];case 2:return[2,t.sent()];case 3:return[2]}}))}))},e.prototype.createComponent=function(e,t){return void 0===t&&(t=!1),f(this,void 0,void 0,(function(){return l(this,(function(n){switch(n.label){case 0:return[4,this.compileComponents()];case 1:return n.sent(),this._fixture=o.TestBed.createComponent(this.hostComponentType),e&&this.setInputs(e),t&&this.detectChanges(),[2,this._fixture]}}))}))},e.prototype.setInputs=function(e,t){void 0===t&&(t=!1),Object.assign(this.hostComponent,e),t&&this.detectChanges()},e.prototype.overrideHostTemplate=function(e){o.TestBed.overrideTemplate(this.hostComponentType,e)},e.prototype.detectChanges=function(e){this._fixture.detectChanges(e)},e.prototype.query=function(e){return this.hostElement.query(r.By.directive(e))},e.prototype.queryComponent=function(e){var t=this.query(e);return t?t.componentInstance:void 0},e.prototype.queryComponentHtml=function(e){var t=this.query(e);return t?t.nativeElement:void 0},e.prototype.queryCss=function(e){return this.hostElement.query(r.By.css(e))},e}(),D=function(e){function t(t){return e.call(this,t)||this}return u(t,e),Object.defineProperty(t.prototype,"element",{get:function(){return this.query(this.componentType)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"htmlElement",{get:function(){return this.queryComponentHtml(this.componentType)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"component",{get:function(){return this.element.componentInstance},enumerable:!0,configurable:!0}),t.ctorParameters=function(){return[{type:n.Injector}]},t.ɵprov=n["ɵɵdefineInjectable"]({factory:function(){return new t(n["ɵɵinject"](n.INJECTOR))},token:t,providedIn:"root"}),t=p([n.Injectable({providedIn:"root"}),a("design:paramtypes",[n.Injector])],t)}(E),q=function(e){function t(t){return e.call(this,t)||this}return u(t,e),Object.defineProperty(t.prototype,"directive",{get:function(){return this.hostComponent.instance},enumerable:!0,configurable:!0}),t.ctorParameters=function(){return[{type:n.Injector}]},t.ɵprov=n["ɵɵdefineInjectable"]({factory:function(){return new t(n["ɵɵinject"](n.INJECTOR))},token:t,providedIn:"root"}),t=p([n.Injectable({providedIn:"root"}),a("design:paramtypes",[n.Injector])],t)}(E);function S(){F=void 0}function A(e,t){return void 0===t&&(t=n.Injector.NULL),Array.isArray(t)&&(t=n.Injector.create({providers:t})),e.create(t)}function R(e){return F&&!e||(F=function(){N||(N=o.getTestBed().platform.injector.get(n.CompilerFactory));return N}().createCompiler(e)),F}afterEach(S),e.Host=E,e.HostComponentService=D,e.HostDirectiveService=q,e.NgxTestingModule=O,e.createModule=function(e,t,o){return void 0===t&&(t=n.Injector.NULL),A(R(o).compileModuleAndAllComponentsSync(e).ngModuleFactory,t)},e.createModuleAsync=function(e,t,o){return void 0===t&&(t=n.Injector.NULL),f(this,void 0,void 0,(function(){return l(this,(function(n){switch(n.label){case 0:return[4,R(o).compileModuleAndAllComponentsAsync(e)];case 1:return[2,A(n.sent().ngModuleFactory,t)]}}))}))},e.getOutputMock=g,e.getTestingForComponent=function(e,t){var n=O.forComponent(e,t),r=function(){return o.TestBed.inject(D)};return{testModule:n,getHost:r,createComponent:function(e,t){return r().createComponent(e,t).then(r)}}},e.getTestingForDirective=function(e,t){var n=O.forDirective(e,t),r=function(){return o.TestBed.inject(q)};return{testModule:n,getHost:r,createComponent:function(e,t){return r().createComponent(e,t).then(r)}}},e.resetModuleCompiler=S,e.setOutputMock=function(e){d=e},e.ɵ0=y,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=orchestrator-ngx-testing.umd.min.js.map