Karma错误 - 没有捕获的浏览器,打开http:// localhost:9876 / [英] Karma error - No captured browser, open http://localhost:9876/

查看:440
本文介绍了Karma错误 - 没有捕获的浏览器,打开http:// localhost:9876 /的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用Karma第一次......遵循这个tutuorial:

解决方案

fixture.debugElement.query 的某些调用与以后的<$ c $调用冲突c> expect(...),在Jasmine的代码中导致看似无限循环。



例如,以下将导致错误匹配#my-id 的对象存在:

  expect(fixture) .debugElement.query(By.css( '#我的ID')))toBeFalsy()。 

在你的情况下,你有一个不同的电话组合,但它是相同的食谱:查询加上一些期望来电。



作为临时解决方法,我们可以使用 queryAll(...)。length 代替:

  expect( fixture.debugElement.queryAll(By.css( '#我-ID'))的长度).toBeFalsy(); 

这是Jasmine中的一个错误,已在这些页面中报告:




I just started to use Karma for first time...Following this tutuorial : https://angular.io/docs/ts/latest/guide/testing.html I am writing simple test to check if the title is correct. I always get this error : "No captured browser, open http://localhost:9876/" .I am using Angular 2 and typescript. These are the versions

"@angular/core": "2.4.10" 
"jasmine-core": "^2.6.2",
"karma": "^1.7.0".

My folder structure looks like this

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';
}

解决方案

Some invocations of fixture.debugElement.query conflict with later invocations of expect(...), causing a seemingly infinite loop in Jasmine's code.

For example, the following will cause the error when an object that matches #my-id exists:

expect(fixture.debugElement.query(By.css('#my-id'))).toBeFalsy();

In your case you had a different combination of calls, but it's the same recipe: query plus some expect calls.

As a temporary workaround, we can use queryAll(...).length instead:

expect(fixture.debugElement.queryAll(By.css('#my-id')).length).toBeFalsy();

This is a bug in Jasmine, and is already reported in these pages:

这篇关于Karma错误 - 没有捕获的浏览器,打开http:// localhost:9876 /的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆