Angular 5 个业力茉莉花-jquery 匹配
Angular 5 karma jasmine-jquery matches
如何整合业力茉莉 jquery 匹配 angular 5
请详细回答
我已经在业力配置中成功加载 jquery
module.exports = function (config) {
config.set({
basePath: '',
frameworks: [ 'jasmine-jquery', 'jasmine', '@angular/cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular/cli/plugins/karma'),
require('karma-jasmine-jquery'),
],
但我不知道如何将其导入规范运行程序
这是我当前的导入工作正常
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MyComponent} from './my.component';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { exec } from 'child_process';
import { DebugElement } from '@angular/core/src/debug/debug_node';
import { By } from '@angular/platform-browser';
使用固定装置很好
beforeEach(() => {
fixture = TestBed.createComponent( MyComponent );
component = fixture.componentInstance;
contenTitleEL = fixture.
debugElement.query( By.css('.contenTitle') ) ;
fixture.detectChanges();
});
使用
测试没问题
it('Should Display contenTitle', () => {
expect( contenTitleEL ).toContain( contentTitle ) ;
});
我想做的是
it('Should Display contenTitle', () => {
expect( contenTitleEL ).toHaveText( contentTitle ) ;
});
请注意,我使用 angular-cli 生成项目
更新
看起来它在工作,即使我有
error TS2339: Property 'toHaveText' does not exist on type
'Matchers'.
关于如何绕过这个错误并在代码完成中使用函数的任何想法
ng 测试有时会因为与打字稿相关的错误而拒绝加载
最终找到答案,看起来你需要添加这个 npm 包
茉莉花-jquery-匹配器
使用
配置排版包
{
....
"compileOnSave": false,
"compilerOptions": {
"types": [
"jasmine",
"jasmine-jquery-matchers"
],
....
}
}
然后最后在spec.ts导入包
import { } from 'jasmine-jquery/lib/jasmine-jquery';
import { } from 'jasmine-jquery-matchers';
如何整合业力茉莉 jquery 匹配 angular 5
请详细回答
我已经在业力配置中成功加载 jquery
module.exports = function (config) {
config.set({
basePath: '',
frameworks: [ 'jasmine-jquery', 'jasmine', '@angular/cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular/cli/plugins/karma'),
require('karma-jasmine-jquery'),
],
但我不知道如何将其导入规范运行程序
这是我当前的导入工作正常
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MyComponent} from './my.component';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { exec } from 'child_process';
import { DebugElement } from '@angular/core/src/debug/debug_node';
import { By } from '@angular/platform-browser';
使用固定装置很好
beforeEach(() => {
fixture = TestBed.createComponent( MyComponent );
component = fixture.componentInstance;
contenTitleEL = fixture.
debugElement.query( By.css('.contenTitle') ) ;
fixture.detectChanges();
});
使用
测试没问题 it('Should Display contenTitle', () => {
expect( contenTitleEL ).toContain( contentTitle ) ;
});
我想做的是
it('Should Display contenTitle', () => {
expect( contenTitleEL ).toHaveText( contentTitle ) ;
});
请注意,我使用 angular-cli 生成项目
更新
看起来它在工作,即使我有
error TS2339: Property 'toHaveText' does not exist on type 'Matchers'.
关于如何绕过这个错误并在代码完成中使用函数的任何想法
ng 测试有时会因为与打字稿相关的错误而拒绝加载
最终找到答案,看起来你需要添加这个 npm 包
茉莉花-jquery-匹配器
使用
配置排版包{
....
"compileOnSave": false,
"compilerOptions": {
"types": [
"jasmine",
"jasmine-jquery-matchers"
],
....
}
}
然后最后在spec.ts导入包
import { } from 'jasmine-jquery/lib/jasmine-jquery';
import { } from 'jasmine-jquery-matchers';