Vla*_*d N 7 testing webpack angular-material angular
我对Angular项目遇到了一些麻烦.我正在学习Angular并且遇到各种各样的错误.
我的项目正在编译并运行良好,但每当我尝试运行"ng测试"以查看我的测试是否成功时,我会收到所有类型的错误.它们看起来像这样:
ERROR in ./node_modules/webdriver-js-extender/node_modules/selenium-webdriver/firefox/extension.js
Module not found: Error: Can't resolve 'fs' in '
Run Code Online (Sandbox Code Playgroud)
要么
ERROR in ./node_modules/tough-cookie/lib/cookie.js
Module not found: Error: Can't resolve 'net' in
Run Code Online (Sandbox Code Playgroud)
等等.我读到了我应该添加目标的fs:webpack配置中的'node'.当我执行一个ng Eject时,webpack配置文件就有了这个
...
"node": {
"fs": "empty",
...
Run Code Online (Sandbox Code Playgroud)
我的测试看起来像这样,我只附加了错误开始的部分:
it('should send credentials on submit', () => {
let fixture = TestBed.createComponent(LoginComponent);
let component: LoginComponent = fixture.componentInstance;
let element = fixture.nativeElement;
fixture.detectChanges();
element.username = expectedUsername;
element.query(by.id('login-username')).value = expectedUsername;
element.query(by.id('login-username')).dispatchEvent(new Event('input'));
element.query(by.id('login-password')).value = expectedPassword;
element.query(by.id('login-password')).dispatchEvent(new Event('input'));
Run Code Online (Sandbox Code Playgroud)
我看到两种潜在的可能性:
您可能错误地导入了模块,使用自动导入的 IDE 很容易做到这一点。有关示例,请参阅此线程的最后评论:https://github.com/angular/angular-cli/issues/8357
Angular 不支持该fs模块(请参阅下面的链接),因为它需要使用浏览器不可用的本机代码。在您提供的代码中,您没有使用fs. 您是否有可能将其导入到项目中的某个位置?如果您没有直接导入它,则您的库之一可能具有. 您可能需要检查您已编辑的库,npm install以查找不支持浏览器的库。https://github.com/angular/angular-cli/issues/8272
正如您帖子中的评论所暗示的那样,如果您添加更多代码(或链接到 GitHub 存储库),我们也许能够提供其他建议。
| 归档时间: |
|
| 查看次数: |
242 次 |
| 最近记录: |