4
我剛剛開始使用Karma第一次...在此tutuorial:https://angular.io/docs/ts/latest/guide/testing.html我正在寫簡單的測試,以檢查標題是否正確。我總是得到這個錯誤:「沒有捕獲瀏覽器,打開http://localhost:9876/」。我正在使用Angular 2和打字稿。這些版本Karma錯誤 - 沒有捕獲的瀏覽器,打開http:// localhost:9876/
"@angular/core": "2.4.10"
"jasmine-core": "^2.6.2",
"karma": "^1.7.0".
我的文件夾結構看起來像這樣
mydashboard
-src
-app
-welcome
-welcome.component.ts
-welcome.component.spec.ts
-karma.conf.js
//karma.conf.js
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: ["src/app/**/*.spec.ts"
],
exclude: [
],
preprocessors: {
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
concurrency: Infinity
})
}
//welcome.component.spec.ts
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { WelcomeComponent } from './welcome.component';
describe('WelcomeComponent (inline template)',() => {
let comp: WelcomeComponent;
let fixture: ComponentFixture<WelcomeComponent>;
let de: DebugElement;
let el: HTMLElement;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ WelcomeComponent ], // declare the test component
});
fixture = TestBed.createComponent(WelcomeComponent);
comp = fixture.componentInstance; // WelcomeComponent test instance
// query for the title <h1> by CSS element selector
de = fixture.debugElement.query(By.css('h1'));
el = de.nativeElement;
});
it('should display original title',() => {
fixture.detectChanges();
expect(el.textContent).toContain(comp.title);
});
});
//welcome.component.ts
import { Component } from '@angular/core';
@Component({
template: '<h1>{{title}}</h1>'
})
export class WelcomeComponent {
title = 'Test Tour of Heroes';
}
這只是一個警告(加上鉻開始後),你的問題在別的地方,你能提供更多的意見嗎?你的配置中沒有'plugins'部分。像'plugins:['karma-jasmine','karma-chrome-launcher']'。請將logLevel改爲config.LOG_DEBUG – Edwin
@Edwin謝謝。我添加了插件並更改了logLevel。我得到相同的警告和錯誤'執行了0的0錯誤(0.023秒/ 0秒)'。我已經在上面添加了其他代碼示例。 welcome.component.spec.ts和welcome.component.ts – Mythri
,現在使用新的日誌級別,你會得到新的輸出嗎?或者是一樣的?然後是問題:你有'node_modules'文件夾中的這些插件嗎? – Edwin