debugtypescriptangularCriticalCanonical
Angular 2 Unit Tests: Cannot find name 'describe'
Viewed 0 times
angularnamefindunitdescribecannottests
Problem
I'm following this tutorial from angular.io
As they said, I've created hero.spec.ts file to create unit tests:
Unit Tests work like a charm. The problem is: I see some errors, which are mentioned in tutorial:
Our editor and the compiler may complain that they don’t know what
and
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.
Example of what I get:
Cannot find name 'describe'.
Cannot find name 'it'.
Cannot find name 'expect'.
What can I do to fix it?
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:
Our editor and the compiler may complain that they don’t know what
itand
expect are because they lack the typing files that describeJasmine. 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.
Example of what I get:
Cannot find name 'describe'.
Cannot find name 'it'.
Cannot find name 'expect'.
What can I do to fix it?
Solution
I hope you've installed -
Then put following import at the top of the
It should solve the problem.
npm install --save-dev @types/jasmineThen put following import at the top of the
hero.spec.ts file -import 'jasmine';It should solve the problem.
Code Snippets
npm install --save-dev @types/jasmineimport 'jasmine';Context
Stack Overflow Q#39020022, score: 434
Revisions (0)
No revisions yet.