ng test如何导致依赖性解析错误?



在使用ng test测试组件时,我遇到了级联类似的错误

Error: ./node_modules/protractor/built/runner.js
Module not found: Error: Can't resolve 'child_process' in '/<path-to-project>/node_modules/protractor/built'
resolve 'child_process' in '/<path-to-project>/node_modules/protractor/built'
Parsed request is a module using description file: /<path-of-project>/node_modules/protractor/package.json (relative path: ./built)
Field 'browser' doesn't contain a valid alias configuration
resolve as module
<continued with other modules e.g. sauceLabs, selenium-webdriver>

该测试只测试组件的一部分是否被定义。

const card = element(By.tag('mat-card-content'))
expect(card).toBeDefined()

解决方案是在ng e2e中使用element而不是单元测试。因此我应该使用

const card = fixture.nativeElement.querySelector('mat-card-content')

选择我的元素。如果你的组件不是像web worker这样的特例你可以使用DOM API与fixture.nativeElement

最新更新