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

查看:93
本文介绍了角度测试失败,无法在"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...

NetworkError:无法在'XMLHttpRequest'上执行'send':无法加载'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/Issues/7296

See details here: https://github.com/angular/angular-cli/issues/7296

为此的简写是:

ng test -sm=false

从6号角开始,命令为:

ng test --source-map=false

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

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