Angular 2 +茉莉花单元测试-出现错误TS2345 [英] Angular 2 + Jasmine Unit Test - Getting Error TS2345

查看:72
本文介绍了Angular 2 +茉莉花单元测试-出现错误TS2345的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了该网站上的单元测试(作者:Torgeir Helgevold)@:TGH http://www.syntaxsuccess.com/viewarticle/angular-2.0-unit-testing 进行单元测试,但出现错误:

I followed the unit testing from this website (author: Torgeir Helgevold) @:TGH http://www.syntaxsuccess.com/viewarticle/angular-2.0-unit-testing to do unit testing, but got an error:

错误:(15,39)TS2345:'FunctionWithParamTokens'类型的参数无法分配给'(done:()=> void)=> void'类型的参数."

"Error:(15, 39) TS2345: Argument of type 'FunctionWithParamTokens' is not assignable to parameter of type '(done: () => void) => void'."

it('should define full name2', inject([DisplayName], (displayName) => {
            displayName.firstName = 'Joe';
            displayName.lastName = 'Smith';
            displayName.generateFullName();
            expect(displayName.fullName).toBe('Joe Smith');
        }));

该网站中的代码是否已过期?谁能给我一些参考,以学习使用Anuglar2 + Jasmine进行单元测试?

Is the code in this website out of date? Can anyone give me some reference to learn unit testing with Anuglar2 + Jasmine?

推荐答案

我也遇到了此错误.问题是我没有从angular2/testing导入beforeEach.

I encountered this error too. The problem was that I was not importing beforeEach from angular2/testing.

import {it, describe, expect, inject, beforeEach} from 'angular2/testing';

describe('Thing', () => {
  let thing: Thing;

  beforeEach(inject([Thing], (t: Thing) => {
    thing = t;
  }));

  it('should do something', () => {
    expect(thing.doSomething()).toBe('I did a thing');
  });
});

这篇关于Angular 2 +茉莉花单元测试-出现错误TS2345的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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