【问题标题】:How can ng test cause dependency resolving errors?ng test 如何导致依赖解析错误?
【发布时间】:2021-02-28 10:49:30
【问题描述】:

在使用 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()

【问题讨论】:

    标签: angular testing jasmine


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2018-08-17
      • 2011-08-04
      • 2020-11-29
      • 2020-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-03
      • 2019-12-05
      相关资源
      最近更新 更多