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

问题描述

我正在关注

正如他们所说,我创建了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:

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

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.

我得到的例子:

找不到名字'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'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 14:32
查看更多