单元测试 – TestBed configureTestingModule定义一个模块中所有
发布时间:2020-12-17 07:15:51 所属栏目:安全 来源:网络整理
导读:是否有一种最佳的方法来定义所有规范所共有的导入,声明,提供者(即一个地方定义的所有规范所共有的模块,就像我们在@NgModule中所做的那样),就像我们在@NgModule中为应用程序单元测试所做的那样. 注意:在beforeEach中调用configureTestingModule,以便TestBed
是否有一种最佳的方法来定义所有规范所共有的导入,声明,提供者(即一个地方定义的所有规范所共有的模块,就像我们在@NgModule中所做的那样),就像我们在@NgModule中为应用程序单元测试所做的那样.
注意:在beforeEach中调用configureTestingModule,以便TestBed可以在每次测试运行之前将自身重置为基本状态.就像文件一样 在我的一个测试规范中,我必须加载相同的模块组件和指令..etc,这也被其他一些规范使用. describe('Component: Login',() => { let loginFixture,loginComponent,loginComponentElement,loginComponentDebugElement; beforeEach(async(() => { TestBed.configureTestingModule({ imports: [FormsModule,ReactiveFormsModule,MaterialRootModule,ModalModule,DatepickerModule,DropdownModule,AccordionModule],//--> here we load n number of mudoles declarations: [LoginComponent,LoginHeaderComponent,LoginColumnComponent,LoginColumnContentComponent,LoginStatusLaneComponent,LoginSettingsComponent,LoginLaneComponent,SortableDirective,WindowHeightDirective,ConfirmDirective,ConfirmPopoverComponent,ConfirmationDialogComponent,ConfirmationDialogDirective],//--> here we load n number of components directive and piper providers: [LoginComponent,MockBackend,BaseRequestOptions,ComponentLoaderFactory,ConfirmOptions,{ provide: Http,useFactory: (backend,options) => new Http(backend,options),deps: [MockBackend,BaseRequestOptions] },{provide: AuthService,useClass: MockAuthService},{provide: AppContextService,useClass: MockAppContextService},{provide: NotificationsService,useClass: MockNotificationsService},{provide: PositioningService}] //--> here we load n number of services }).compileComponents(); loginFixture = TestBed.createComponent(LoginComponent); loginComponent = loginFixture.componentInstance; loginComponentElement = LoginFixture.nativeElement; loginComponentDebugElement = LoginFixture.debugElement; })); it('should have a defined component',() => { expect(LoginComponent).toBeDefined(); }); }); 注意:Git Angular issue TestBed.configureTestingModule Performance Issue 在运行所有spec.ts文件并为每个规范注入相应的依赖项之前,是否有任何模式可以使它像加载所有这些模块组件等一样常见.任何帮助都会很棒. 解决方法
你的回答是不完整的,你已经开始期待了.
但我希望它能帮到你一点点. 路由器stubs.ts //----------Default Import------------ import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { HttpModule } from '@angular/http'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; ...snip... export const test_imports = [ BrowserModule,FormsModule,HttpModule,BrowserAnimationsModule ]; 每个test.spec.ts import { test_imports } from '../testing/router-stubs'; ..snip.. imports: [test_imports], 但是提供者/声明不能以相同的方式使用. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- WebService 的一些基本概念-3 (Target namespace,WSDL 和总
- 使用bootstrap typeahead插件实现输入框自动补全之问题及解
- .net Remoting vs WebServices (还没来得及翻译,先凑合着
- macos – hdiutil在终端窗口中工作但不在shell脚本中工作
- scala – 如何将WebJars添加到我的Play应用程序?
- Angular.js内置服务
- angularjs – 如何将一个“模型”映射到两个字段?
- bash:如何连接两个命令的输出,以便我可以将它们管理到第三
- ng-click得到当前元素,angular.element()用法
- SAP#有关于Webservice创建中Map Names复选框的效果