单元测试 – Angular2:“TypeError:无法读取未定义的属性’cre
发布时间:2020-12-17 17:39:42 所属栏目:安全 来源:网络整理
导读:单元测试 import {Goal} from '../../providers/goal/goal';import {GoalSettingsPage} from './goal-settings';import {Modal,Alert,NavParams,ViewController,Events} from 'ionic-angular';import {provide,ReflectiveInjector,Component} from '@angular
单元测试
import {Goal} from '../../providers/goal/goal'; import {GoalSettingsPage} from './goal-settings'; import {Modal,Alert,NavParams,ViewController,Events} from 'ionic-angular'; import {provide,ReflectiveInjector,Component} from '@angular/core' import {FormBuilder} from '@angular/common'; import { beforeEach,beforeEachProviders,describe,expect,it,xit,TestComponentBuilder,ComponentFixture,inject,async } from '@angular/core/testing'; describe('Goal Settings',() => { it('should display header title: "Some Title"',inject([TestComponentBuilder],(tcb: TestComponentBuilder) => { return tcb.createAsync(GoalSettingsPage).then((fixture) => { fixture.detectChanges(); var compiled = fixture.debugElement.nativeElement; expect(compiled.innerHTML).toContain('ion-title'); expect(compiled.querySelector('span')) .toHaveText('Cancel'); expect(compiled.querySelector('ion-title') .innerText).toBe('DrEvil'); }); })); 错误消息
问题 Pascal在这里写道:http://5thingsangular.github.io/2016/04/11/issue-1.html那个injectAsync已被弃用,那么我如何像酷帅一样创建Async? 更新:重启gulp后错误消失.现在我明白了:
UPDATE2: 通过注入描述范围而不是注入范围来解决: let tcb; //setup beforeEachProviders(() => [ TestComponentBuilder ]); beforeEach(inject([TestComponentBuilder],_tcb => { tcb = _tcb })); 新错误
解决方法
导入TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS和TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,如下所示:
import { TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS,TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,} from '@angular/platform-browser-dynamic/testing'; setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS); ..解决了我的上一个错误. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |