加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular测试失败,无法在’XMLHttpRequest’上执行’send’

发布时间:2020-12-17 07:54:41 所属栏目:安全 来源:网络整理
导读:我正在尝试测试我的角度4.1.0组件 – export class CellComponent implements OnInit { lines: ObservableArrayILine; @Input() dep: string; @Input() embedded: boolean; @Input() dashboard: boolean; constructor( public dataService: CellService,priv
我正在尝试测试我的角度4.1.0组件 –
export class CellComponent implements OnInit {
  lines: Observable<Array<ILine>>;
  @Input() dep: string;
  @Input() embedded: boolean;
  @Input() dashboard: boolean;
  constructor(
    public dataService: CellService,private route: ActivatedRoute,private router: Router,private store: Store<AppStore>) {
  }
}

但是,一个简单的“应该创建”测试会引发这个神秘的错误……

NetworkError: Failed to execute ‘send’ on ‘XMLHttpRequest’: Failed to load ‘ng:///DynamicTestModule/module.ngfactory.js’.

所以我发现this问题,这表明问题是组件有@Input)_ params没有设置,但是,如果我修改我的测试如下:

it('should create',inject([CellComponent],(cmp: CellComponent) => {
    cmp.dep = '';
    cmp.embedded = false;
    cmp.dashboard = false;
    expect(cmp).toBeTruthy();
  }));

然后我仍然得到相同的问题,同样,如果我从组件中删除@Input()注释,仍然没有区别.我怎样才能通过这些测试?

这是新的Angular Cli的问题.使用–sourcemaps = false运行测试,您将获得正确的错误消息.

详情请见:https://github.com/angular/angular-cli/issues/7296

编辑:

这方面的简写是:

ng test -sm = false

从角度6开始,命令是:

ng test –source-map = false

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读