加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

单位测试 – 角度2单位测试:找不到名称’描述’

发布时间:2020-12-17 08:23:48 所属栏目:安全 来源:网络整理
导读:我在追踪 this tutorial from angular.io 正如他们所说,我创建了hero.spec.ts文件来创建单元测试: import { Hero } from './hero';describe('Hero',() = { it('has name',() = { let hero: Hero = {id: 1,name: 'Super Cat'}; expect(hero.name).toEqual('
我在追踪 this tutorial from angular.io

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

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',name: 'Super Cat'};
    expect(hero.id).toEqual(1);
  });
});

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

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.

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

我得到的例子:

Cannot find name ‘describe’.

Cannot find name ‘it’.

Cannot find name ‘expect’.

我可以做些什么来解决它?

我希望你已经安装 –

npm install –save-dev @ types / jasmine

然后将以下导入到hero.spec.ts文件的顶部 –

从茉莉花进口{}

应该解决问题。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读