Angular 测试失败,无法在“XMLHttpRequest"上执行“发送" [英] Angular tests failing with Failed to execute 'send' on 'XMLHttpRequest'

查看:33
本文介绍了Angular 测试失败,无法在“XMLHttpRequest"上执行“发送"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试测试我的 angular 4.1.0 组件 -

I am trying to test my angular 4.1.0 component -

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>) {
  }
}

然而,一个简单的应该创建"测试会抛出这个神秘的错误......

However, a simple "should create" test throws this cryptic error...

网络错误:无法在XMLHttpRequest"上执行发送":无法加载ng:///DynamicTestModule/module.ngfactory.js".

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

所以我发现了这个 问题,这表明问题在于组件具有未设置的 @Input)_ 参数,但是,如果我像这样修改测试:

so I found this question, which suggests that the issue is the component has @Input)_ params which aren't set, however, if I modify my test like so:

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

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

then I still get the same issue, similarly, if I remove the @Input() annotations from the component, still no difference. How can I get these tests to pass?

推荐答案

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

This is a problem of the new Angular Cli. Run your test with --sourcemaps=false and you will get the right error messages.

在此处查看详细信息:https://github.com/angular/angular-cli/问题/7296

简写是:

ng test -sm=false

从 angular 6 开始,命令是:

ng test --source-map=false

这篇关于Angular 测试失败,无法在“XMLHttpRequest"上执行“发送"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆