角度测试失败,无法在"XMLHttpRequest"上执行“发送" [英] Angular tests failing with Failed to execute 'send' on '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屋!