Angular 2单元测试:找不到名称'describe' [英] Angular 2 Unit Tests: Cannot find name 'describe'

查看:1289
本文介绍了Angular 2单元测试:找不到名称'describe'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注 angular.io的本教程

正如他们所说,我创建了hero.spec.ts文件来创建单元测试:

As they said, I've created hero.spec.ts file to create unit tests:

import { Hero } from './hero';
describe('Hero', () => {
  it('has name', () => {
    let hero: Hero = {id: 1, name: 'Super Cat'};
    expect(hero.name).toEqual('Super Cat');
  });
  it('has id', () => {
    let hero: Hero = {id: 1, name: 'Super Cat'};
    expect(hero.id).toEqual(1);
  });
});

单元测试就像魅力一样。问题是:我看到一些错误,在教程中提到:

Unit Tests work like a charm. The problem is: I see some errors, which are mentioned in tutorial:


我们的编辑和编译器可能会抱怨他们不知道什么
期望是因为他们缺少描述
Jasmine的输入文件。我们现在可以忽略那些烦人的抱怨,因为它们是
无害。

Our editor and the compiler may complain that they don’t know what it and expect are because they lack the typing files that describe Jasmine. We can ignore those annoying complaints for now as they are harmless.

他们确实忽略了它。即使这些错误是无害的,但当我收到大量错误时,它在我的输出控制台中看起来并不好。

And they indeed ignored it. Even though those errors are harmless, it doesn't look good in my output console when I receive bunch of them.

我得到的例子:


找不到名称'describe'。

Cannot find name 'describe'.

找不到名字'it'。

找不到'期望'这个名字。

Cannot find name 'expect'.

我该怎么办才能修复它?

What can I do to fix it?

推荐答案

我希望你已经安装了 -

I hope you've installed -

npm install --save-dev @ types / jasmine

然后将以下导入放在的顶部hero.spec.ts file -

Then put following import at the top of the hero.spec.ts file -

从'jasmine'导入{};

它应该可以解决问题。

这篇关于Angular 2单元测试:找不到名称'describe'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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