我在追踪
this tutorial from angular.io
@H_403_35@
我希望你已经安装 –
正如他们所说,我创建了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
andexpect
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文件的顶部 –
从茉莉花进口{}
应该解决问题。