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

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

问题描述

我正在关注 来自 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:

我们的编辑器和编译器可能会抱怨他们不知道 it 是什么和 expect 是因为它们缺少描述茉莉花.我们可以暂时忽略那些烦人的抱怨无害.

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.

我得到的示例:

找不到名称描述".

找不到名称它".

找不到名字'expect'.

Cannot find name 'expect'.

我能做些什么来解决它?

What can I do to fix it?

推荐答案

希望你已经安装了-

npm install --save-dev @types/jasmine

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

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

import 'jasmine';

应该能解决问题.

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

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