Erro de karma - nenhum navegador capturado, abra http: // localhost: 9876 /
Comecei a usar o Karma pela primeira vez ... Seguindo este tutorial:https://angular.io/docs/ts/latest/guide/testing.html Estou escrevendo um teste simples para verificar se o título está correto. Eu sempre entendo issoerror: "Nenhum navegador capturado, abertohttp: // localhost: 9876 /" .Estou usando Angular 2 e texto datilografado. Estas são as versões
"@angular/core": "2.4.10"
"jasmine-core": "^2.6.2",
"karma": "^1.7.0".
Minha estrutura de pastas fica assim
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';
}