标签: karma-jasmine

Angular测试失败,无法在'XMLHttpRequest'上执行'send'

我正在尝试测试我的角度4.1.0组件 -

export class CellComponent implements OnInit {
  lines: Observable<Array<ILine>>;
  @Input() dep: string;
  @Input() embedded: boolean;
  @Input() dashboard: boolean;
  constructor(
    public dataService: CellService,
    private route: ActivatedRoute,
    private router: Router, private store: Store<AppStore>) {
  }
}
Run Code Online (Sandbox Code Playgroud)

但是,一个简单的"应该创建"测试会引发这个神秘的错误......

NetworkError:无法在'XMLHttpRequest'上执行'send':无法加载'ng:///DynamicTestModule/module.ngfactory.js'.

所以我发现了这个问题,这表明问题是组件有@Input)_没有设置的参数,但是,如果我像这样修改我的测试:

  it('should create', inject([CellComponent], (cmp: CellComponent) => {
    cmp.dep = '';
    cmp.embedded = false;
    cmp.dashboard = false;
    expect(cmp).toBeTruthy();
  }));
Run Code Online (Sandbox Code Playgroud)

然后我仍然得到相同的问题,同样,如果我@Input()从组件中删除注释,仍然没有区别.我怎样才能通过这些测试?

unit-testing karma-jasmine angular-cli angular

134
推荐指数
5
解决办法
5万
查看次数

CUSTOM_ELEMENTS_SCHEMA添加到NgModule.schemas仍然显示错误

我刚从Angular 2 rc4升级到rc6并且遇到了麻烦.

我在控制台上看到以下错误:

Unhandled Promise rejection: Template parse errors:
'cl-header' is not a known element:
1. If 'cl-header' is an Angular component, then verify that it is part of this module.
2. If 'cl-header' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message. ("<main>
    [ERROR ->]<cl-header>Loading Header...</cl-header>
    <div class="container-fluid">
      <cl-feedbackcontai"): AppComponent@1:4
Run Code Online (Sandbox Code Playgroud)

这是我的标题组件:

import { Component } from '@angular/core';
import { Router } from '@angular/router';

// own service
import { AuthenticationService } …
Run Code Online (Sandbox Code Playgroud)

karma-jasmine angular

119
推荐指数
9
解决办法
19万
查看次数

如何在我的Karma/Jasmine测试中调试"[object ErrorEvent] thrown"错误?

我有几个失败的测试只输出[object ErrorEvent] thrown.我在控制台中看不到任何可以帮助我查明违规代码的内容.我需要做些什么来追踪这些?

[编辑]:我正在运行Karma v1.70,Jasmine v2.7.0

karma-jasmine angular-cli angular

104
推荐指数
5
解决办法
6万
查看次数

没有"框架:茉莉花"的提供者!(解决:框架:茉莉花)

当我运行命令时,grunt我收到以下警告:

Running "karma:unit" (karma) task
Warning: No provider for "framework:jasmine"! (Resolving: framework:jasmine) Use --force to continue.
Run Code Online (Sandbox Code Playgroud)

有人知道如何解决这个问题吗?

gruntjs karma-jasmine

98
推荐指数
5
解决办法
4万
查看次数

Karma:从命令行运行单个测试文件

所以,我一直在寻找这个,在这里找到"类似"的答案,但不完全是我想要的.

现在,如果我想测试与因缘一个单一的文件,我需要做的fit(),fdescribe()对有问题的文件...

但是,我真正想要的是能够使用配置文件调用karma,并将其指向特定文件,因此我根本不需要修改文件,即:

karma run --conf karma.conf.js --file /path/to/specific/test_file.js

是否有可能做到这一点?还是有帮助?(使用grunt或gulp?)

javascript gruntjs karma-runner karma-jasmine gulp

87
推荐指数
3
解决办法
9万
查看次数

在编写Karma-Jasmine单元测试用例时,"错误:没有路由器的提供者"

我们已经完成了一个angular2项目设置和内部创建了一个模块(my-module),并在该模块内部使用以下cmd命令创建了一个组件(my-new-component):

ng new angular2test
cd angular2test
ng g module my-module
ng generate component my-new-component
Run Code Online (Sandbox Code Playgroud)

在创建设置和所有组件之后,我们ng test从angular2test文件夹中的cmd 运行命令.

下面的文件是我的my-new-component.component.ts文件:

import { Component, OnInit } from '@angular/core';
import { Router, Routes, RouterModule } from '@angular/router';
import { DummyService } from '../services/dummy.service';

@Component({
  selector: 'app-my-new-component',
  templateUrl: './my-new-component.component.html',
  styleUrls: ['./my-new-component.component.css']
})
export class MyNewComponentComponent implements OnInit {

  constructor(private router : Router, private dummyService:DummyService) { }

  ngOnInit() {
  }
    redirect() : void{
        //this.router.navigate(['/my-module/my-new-component-1'])
    }
}
Run Code Online (Sandbox Code Playgroud)

下面的文件是我的my-new-component.component.spec.ts文件:

/* tslint:disable:no-unused-variable */
import { …
Run Code Online (Sandbox Code Playgroud)

unit-testing karma-jasmine angular2-routing angular-cli angular

87
推荐指数
3
解决办法
5万
查看次数

错误:您需要包含一些实现__karma __.start方法的适配器

我正在尝试为我的一个项目添加一些单元测试.

到目前为止,我已经安装并配置了业力,并安装了茉莉.我的文件test/夹中有一个测试文件.

karma服务器已启动,浏览器页面已准备就绪,但karma run失败如下:

$ karma run karma-conf.js 
[2014-06-14 15:19:11.046] [DEBUG] config - Loading config /foo/test/karma-conf.js
Waiting for previous execution...
Chrome 35.0.1916 (Linux) ERROR
  You need to include some adapter that implements __karma__.start method!
Run Code Online (Sandbox Code Playgroud)

此错误消息不适合Google.

这是显而易见的,还是我需要提供更多信息?

karma-runner karma-jasmine

85
推荐指数
6
解决办法
5万
查看次数

Angular Karma Jasmine错误:非法状态:无法加载指令的摘要

我正在开发一个github存储库(带有角度4和angular-cli),我有一些测试,Karma和Jasmine在master分支中工作.

现在我正在尝试添加延迟加载功能,我已经创建了一个新的分支,你可以在这里看到.

问题是,之前的测试,现在他们没有.这很有趣,因为只有延迟加载模块的测试失败了......

这是代码和错误:

import {async, TestBed} from '@angular/core/testing';
import {APP_BASE_HREF} from '@angular/common';
import {AppModule} from '../../app.module';
import {HeroDetailComponent} from './hero-detail.component';

describe('HeroDetailComponent', () => {
  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [AppModule
      ],
      providers: [
        {provide: APP_BASE_HREF, useValue: '/'}
      ],
    }).compileComponents();
  }));

  it('should create hero detail component', (() => {
    const fixture = TestBed.createComponent(HeroDetailComponent);
    const component = fixture.debugElement.componentInstance;
    expect(component).toBeTruthy();
  }));
});
Run Code Online (Sandbox Code Playgroud)

错误是这样的:

Chrome 58.0.3029 (Mac OS X 10.12.6) HeroDetailComponent should create hero detail component FAILED
    Error: Illegal …
Run Code Online (Sandbox Code Playgroud)

javascript karma-runner karma-jasmine angular-cli angular

83
推荐指数
2
解决办法
4万
查看次数

Angular 2 Karma Test'component-name'不是已知元素

在AppComponent中,我在HTML代码中使用nav组件.用户界面看起来很好.做服务时没有错误.当我查看应用程序时,控制台中没有错误.

但是当我为我的项目运行Karma时,出现了一个错误:

Failed: Template parse errors: 
'app-nav' is not a known element:
1. If 'app-nav' is an Angular component, then verify that it is part of this module.
2. If 'app-nav' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
Run Code Online (Sandbox Code Playgroud)

在我的app.module.ts中:

有:

import { NavComponent } from './nav/nav.component';
Run Code Online (Sandbox Code Playgroud)

它也在NgModule的声明部分

@NgModule({
  declarations: [
    AppComponent,
    CafeComponent,
    ModalComponent,
    NavComponent,
    NewsFeedComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    JsonpModule,
    ModalModule.forRoot(),
    ModalModule,
    NgbModule.forRoot(),
    BootstrapModalModule,
    AppRoutingModule
  ], …
Run Code Online (Sandbox Code Playgroud)

javascript node.js typescript karma-jasmine angular

81
推荐指数
2
解决办法
4万
查看次数

Angular 2 Testing - 异步函数调用 - 何时使用

在Angular 2中进行测试时,何时在TestBed中使用异步函数?

你什么时候用的?

 beforeEach(() => {
        TestBed.configureTestingModule({
            declarations: [MyModule],
            schemas: [NO_ERRORS_SCHEMA],
        });
    });
Run Code Online (Sandbox Code Playgroud)

你何时使用它?

beforeEach(async(() => {
    TestBed.configureTestingModule({
        declarations: [MyModule],
        schemas: [NO_ERRORS_SCHEMA],
    });
}));
Run Code Online (Sandbox Code Playgroud)

任何人都可以启发我吗?

unit-testing karma-jasmine angular2-testing angular angular-test

74
推荐指数
2
解决办法
3万
查看次数