- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已将 ng-select 组件 ( https://github.com/ng-select/ng-select ) 导入到我的 Angular 应用程序中,并且在运行该应用程序时不会抛出任何控制台错误,并且按预期工作。但是,当使用 Jasmine 运行我的 Angular 单元测试时,它会导致错误。
我已经将 NgSelectModule 导入到 imports 数组下的 app.module.ts 文件中,并且我还通过 declarations 数组将 NgSelectComponent 导入到我的 configuration.component.spec.ts 文件中:
import { NgSelectComponent } from '@ng-select/ng-select';
describe('Test Configuration Component',
() => {
let component: ConfigurationComponent;
let fixture: ComponentFixture<ConfigurationComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ConfigurationComponent, NgSelectComponent],
imports: [FormsModule],
providers: [{ provide: APIService, useClass: APIServiceMock }, Helper]
});
fixture = TestBed.createComponent(ConfigurationComponent);
component = fixture.componentInstance;
});
我的单元测试如下所示:
it('check that array of employees got binded to accounts', async () => {
fixture.detectChanges();
let employeeAccounts = [
{ "employeeAccountId": 1, "employeeId": 1, "name": "Name", "descriptor": "descriptor", "street": "Street", "postcode": "postcode", "state": "VIC", "city": "Melb", "country": "AU", "phone": "3123", "MCC": "MCC" },
{ "employeeAccountId": 2, "employeeId": 1, "name": "Name2", "descriptor": "descriptor2", "street": "Street2", "postcode": "postcode2", "state": "VIC2", "city": "Melb2", "country": "AU2", "phone": "3123", "MCC": "MCC2" }];
component.employeeAccounts = employeeAccounts;
component.ngOnInit();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(component.employeeAccounts[1]).toEqual(employeeAccounts[1]);
});
});
配置组件中 ng-select 的 HTML 如下所示:
<ng-select [(ngModel)]="selectedEmployeeAccountId" [items]="employeeAccounts" (change)="accountSelected()" [disabled]="isLoadingAccounts" [loading]="isLoadingAccounts" bindLabel="name" bindValue="employeeAccountId" placeholder="Please Select"></ng-select>
由于 Angular 5 的兼容性问题,我不得不使用旧版本的 ng-select (v 1.5.2)。
单元测试错误:
HeadlessChrome 0.0.0 (Windows 10 0.0.0) Test Configuration Component check that array of employees got binded to accounts FAILED
Error: Template parse errors:
Can't bind to 'virtualScroll' since it isn't a known property of 'ng-dropdown-panel'.
1. If 'virtualScroll' is an Angular directive, then add 'CommonModule' to the '@NgModule.imports' of this component.
2. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
<ng-dropdown-panel *ngIf="isOpen"
class="ng-dropdown-panel"
[ERROR ->][virtualScroll]="virtualScroll"
[bufferAmount]="bufferAmount"
[appendTo]="appendTo"
"): ng:///DynamicTestModule/NgSelectComponent.html@47:4
Can't bind to 'bufferAmount' since it isn't a known property of 'ng-dropdown-panel'.
1. If 'bufferAmount' is an Angular directive, then add 'CommonModule' to the '@NgModule.imports' of this component.
2. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
class="ng-dropdown-panel"
[virtualScroll]="virtualScroll"
[ERROR ->][bufferAmount]="bufferAmount"
[appendTo]="appendTo"
[position]="dropdownPosition"
"): ng:///DynamicTestModule/NgSelectComponent.html@48:4
Can't bind to 'appendTo' since it isn't a known property of 'ng-dropdown-panel'.
1. If 'appendTo' is an Angular directive, then add 'CommonModule' to the '@NgModule.imports' of this component.
2. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
[virtualScroll]="virtualScroll"
[bufferAmount]="bufferAmount"
[ERROR ->][appendTo]="appendTo"
[position]="dropdownPosition"
[headerTemplate]="headerTemplate"
"): ng:///DynamicTestModule/NgSelectComponent.html@49:4
Can't bind to 'position' since it isn't a known property of 'ng-dropdown-panel'.
1. If 'position' is an Angular directive, then add 'CommonModule' to the '@NgModule.imports' of this component.
2. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
[bufferAmount]="bufferAmount"
[appendTo]="appendTo"
[ERROR ->][position]="dropdownPosition"
[headerTemplate]="headerTemplate"
[footerTemplate]="footerTempl"): ng:///DynamicTestModule/NgSelectComponent.html@50:4
Can't bind to 'headerTemplate' since it isn't a known property of 'ng-dropdown-panel'.
1. If 'headerTemplate' is an Angular directive, then add 'CommonModule' to the '@NgModule.imports' of this component.
2. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
[appendTo]="appendTo"
[position]="dropdownPosition"
[ERROR ->][headerTemplate]="headerTemplate"
[footerTemplate]="footerTemplate"
[items]="itemsList.filter"): ng:///DynamicTestModule/NgSelectComponent.html@51:4
Can't bind to 'footerTemplate' since it isn't a known property of 'ng-dropdown-panel'.
1. If 'footerTemplate' is an Angular directive, then add 'CommonModule' to the '@NgModule.imports' of this component.
2. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
[position]="dropdownPosition"
[headerTemplate]="headerTemplate"
[ERROR ->][footerTemplate]="footerTemplate"
[items]="itemsList.filteredItems"
(update)="viewPortItems ="): ng:///DynamicTestModule/NgSelectComponent.html@52:4
Can't bind to 'items' since it isn't a known property of 'ng-dropdown-panel'.
1. If 'items' is an Angular directive, then add 'CommonModule' to the '@NgModule.imports' of this component.
2. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
[headerTemplate]="headerTemplate"
[footerTemplate]="footerTemplate"
[ERROR ->][items]="itemsList.filteredItems"
(update)="viewPortItems = $event"
(scrollToEnd)="scrollToEn"): ng:///DynamicTestModule/NgSelectComponent.html@53:4
'ng-dropdown-panel' is not a known element:
1. If 'ng-dropdown-panel' is an Angular component, then verify that it is part of this module.
2. If 'ng-dropdown-panel' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
</span>
</div>
[ERROR ->]<ng-dropdown-panel *ngIf="isOpen"
class="ng-dropdown-panel"
[virtualScroll]="virtualScroll"
"): ng:///DynamicTestModule/NgSelectComponent.html@45:0
at syntaxError node_modules/@angular/compiler/esm5/compiler.js:486:22)
at TemplateParser.webpackJsonp../node_modules/@angular/compiler/esm5/compiler.js.TemplateParser.parse node_modules/@angular/compiler/esm5/compiler.js:24674:1)
at JitCompiler.webpackJsonp../node_modules/@angular/compiler/esm5/compiler.js.JitCompiler._parseTemplate node_modules/@angular/compiler/esm5/compiler.js:34629:1)
at JitCompiler.webpackJsonp../node_modules/@angular/compiler/esm5/compiler.js.JitCompiler._compileTemplate node_modules/@angular/compiler/esm5/compiler.js:34604:1)
at http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/compiler/esm5/compiler.js:34505:48
at Set.forEach (<anonymous>)
at JitCompiler.webpackJsonp../node_modules/@angular/compiler/esm5/compiler.js.JitCompiler._compileComponents node_modules/@angular/compiler/esm5/compiler.js:34505:1)
at http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/compiler/esm5/compiler.js:34393:1
at Object.then node_modules/@angular/compiler/esm5/compiler.js:475:33)
at JitCompiler.webpackJsonp../node_modules/@angular/compiler/esm5/compiler.js.JitCompiler._compileModuleAndAllComponents node_modules/@angular/compiler/esm5/compiler.js:34391:1)
Failed: Cannot read property 'detectChanges' of undefined
TypeError: Cannot read property 'detectChanges' of undefined
at Object.<anonymous> src/app/configuration/configuration.component.spec.ts:87:17)
at step (http://localhost:9876/_karma_webpack_/main.bundle.js:89:23)
at Object.next (http://localhost:9876/_karma_webpack_/main.bundle.js:70:53)
at http://localhost:9876/_karma_webpack_/main.bundle.js:64:71
at new ZoneAwarePromise node_modules/zone.js/dist/zone.js:891:1)
at webpackJsonp../src/app/configuration/configuration.component.spec.ts.__awaiter (http://localhost:9876/_karma_webpack_/main.bundle.js:60:12)
at UserContext.<anonymous> src/app/configuration/configuration.component.spec.ts:86:66)
at ZoneDelegate.webpackJsonp../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke node_modules/zone.js/dist/zone.js:388:1)
at ProxyZoneSpec.webpackJsonp../node_modules/zone.js/dist/zone-testing.js.ProxyZoneSpec.onInvoke node_modules/zone.js/dist/zone-testing.js:288:1)
at ZoneDelegate.webpackJsonp../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke node_modules/zone.js/dist/zone.js:387:1)
我相信这可能是因为我使用的 ng-select 版本没有导入所有必要的依赖项,但后来我在前端成功使用了下拉菜单,所以我认为这可能是一个单独的问题。
任何帮助识别问题的帮助都会很棒。
谢谢!
最佳答案
将 NgSelectModule 添加到您的导入中,这为我修复了错误。
import {
NgSelectModule
} from '@ng-select/ng-select';
describe('Test Configuration Component',
() => {
let component: ConfigurationComponent;
let fixture: ComponentFixture < ConfigurationComponent > ;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ConfigurationComponent],
imports: [FormsModule, NgSelectModule],
providers: [{
provide: APIService,
useClass: APIServiceMock
}, Helper]
});
fixture = TestBed.createComponent(ConfigurationComponent);
component = fixture.componentInstance;
});
编辑:格式化。
关于javascript - 使用 ng-select 包的 Jasmine 单元测试错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50559812/
我使用 File > Settings > JavaScript > Libraries 在 Webstorm 8.0.4 中设置 Jasmine 集成。我添加了 karma-jasmine带有我的
假设我有 spyOn($cookieStore,'get').and.returnValue('abc'); 对于我的用例来说,这太笼统了。任何时候我们打电话 $cookieStore.get('so
我正在阅读有关 Jasmine 测试的教程,它建议您应该使用标准 Jasmine 目录树结构(这似乎与 RSpec 目录树结构有关)。我用谷歌搜索了一个小时,找不到任何有关此标准目录树的信息。 考虑到
问题 如何使用Jasmine插件通过Jasmine运行Karma时更新所使用的karma-jasmine的版本? 仅当Jasmine插件集成了较新版本的karma-jasmine时,才会更新Jasmi
我想在每个规范执行后获得测试的通过或失败状态: var passed = jasmine.getEnv().currentSpec.results().passed(); if (!pas
我有一个与 Karma 一起运行的 Jasmine 测试: describe('When a logged in user chooses Rent and Payment PIN is enable
在我的新手理解中,Jasmine 提供了以下语法: describe('FooBar', function(){ it('should blah-blah', function(){ ex
我认为我通过编写这样的 Jasmine 模拟取得了很好的进展。但我无法修复这个错误。 spyOn 方法实际上是如何工作的?事实上这种方法似乎被广泛使用。 2.0 有什么变化 describe('Tes
有大量文档展示了如何将匹配器添加到 Jasmine 规范(例如 here )。 有人找到了向整个环境添加匹配器的方法吗?我想创建一组有用的匹配器,供任何和所有测试调用,而无需在我的规范中复制粘贴。 目
我正在尝试查找所有现有 Jasmine 期望匹配器(例如“toContain”等)的列表... 哪里可以找到这个?我搜索了一段时间,但找不到像 api 这样的东西。 Jasmine 网站也没有任何类型
我熟悉 python 单元测试测试,如果断言失败,该测试将被标记为“失败”,并继续进行其他测试。另一方面,即使其中一个失败, Jasmine 也会继续完成所有期望。如何让 Jasmine 在第一个期望
工具:Protractor 3.3.0、Jasmine 2.4.1、Selenium Standalone Server。 我有一个测试套件,里面有大量的 spec.js 文件,每个文件都包含我的应用
Jasmine 中是否有与 console.log 类似的方法?如果我想注销我 mock 的 $controller 或服务的值,有没有办法做到这一点? 最佳答案 您应该只使用 console.log
我已经通过运行 npm install jasmine -g 全局安装了 jasmine。 运行 jasmine -v 给我 jasmine v2.5.0 jasmine-core v2.5.0 然后
我有gulp-jasmine-phantom正在运行,但我得到 ReferenceError: Tictactoe is not defined 。我感觉我犯了一些根本性的错误。 我的文件结构: gu
我已经创建了一个 JavaScript 项目,需要使用 Jasmine 进行单元测试。我遵循了以下步骤: 1. npm install jasmine --save-dev - 从项目根目录 2.现在
我正在为我的应用程序使用 Yeoman+Angular Generator,我一直在努力与 Jasmine 相处!这就是我卡住的地方。我希望能够在 Jasmine 测试中使用 jQuery 选择器。我
it('should for something', function check(done) { browser.sleep(2000); $('.csTx').isPresent().th
Javascript 编码有点新,所以请耐心等待。 我阅读了以下链接 jasmine with jscoverage automated testing 但是,由于我没有 Ruby 项目,因此它似乎不
在Jasmine headless (headless)Webkit中运行测试时,我遇到了一个简单的TypeError: 'undefined' is not an object失败。但是没有提示在哪
我是一名优秀的程序员,十分优秀!