Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I import 'createSpyObj' from jasmine for tests written in Typescript?

How do I import the createSpyObj property from jasmine?

I have installed @types/jasmine and jasmine-core via npm.

I have tried importing jasmine as:

import jasmine from 'jasmine;
import { createSpyObj } from 'jasmine'; //triggers import error in IDE
import * as jasmine from 'jasmine'; //triggers import error in IDE

None of these allow me to access the createSpyObj without an error thrown in my WebStorm IDE.

IDE error showing it cannot find 'createSpyObj' method on jasmine

More information:

I see a namespace declaration for createSpyObj in the typings file. It is nested in the jasmine namespace. This is unlike expect, it, which are global declarations, but shouldn't I be able to access it with jasmine.createSpyObj?

jasmine typings file

Related, but not duplicate of

How to import 'describe', 'expect' and 'it' into a typescript tests for IDE to not to highlight them and

Unit testing using Jasmine and TypeScript

like image 580
user2954463 Avatar asked Sep 29 '17 15:09

user2954463


1 Answers

jasmine uses require syntax, so you must too.

import createSpyObj = jasmine.createSpyObj;
like image 84
user2954463 Avatar answered Nov 04 '22 12:11

user2954463