0

I'm trying to use something I've seen around that looks like:

let test1 = {value:5};
let test2 = {value:5};

// Returns true.
expect(test1).toEqual(test2);

However, it's just giving me an error:

EXCEPTION: Error in :0:0 caused by: expect is not defined

I understand these functions come from Jasmine, and I read somewhere that as of Angular RC5 that they don't need to be imported, as they are global. Is that true? If not, how should I import them?

BBaysinger
  • 6,614
  • 13
  • 63
  • 132
  • angular doesn't have expect by default , https://github.com/mjackson/expect – Ahmed Eid Mar 29 '17 at 20:00
  • I would recommend using: [mocha](https://mochajs.org/) for testing framework, and [chai](http://chaijs.com/) for assertion library. from there you can do: `const { expect } = require('chai')` – rc_dz Mar 29 '17 at 20:01
  • @aeid, Thanks. Now I've tried to use mjackson/expect, but I get "Cannot find module 'expect'." I used "npm install --save expect" to install it. – BBaysinger Mar 29 '17 at 20:06
  • @cXoltero I tried "import { expect } from 'chai';" and got "Cannot find module 'chai'", then I tried your "const { expect } = require('chai')", and got "Cannot find name 'require'.". – BBaysinger Mar 29 '17 at 20:14
  • Reference the following [typescript](http://stackoverflow.com/questions/31173738/typescript-getting-error-ts2304-cannot-find-name-require) – rc_dz Mar 29 '17 at 20:41

1 Answers1

-1

As far I can understand you tried to write some unit tests, yes?
"I'm trying to use something I've seen around that looks like" - this sentence sounds like:
"They are doing like this so I should too".

In comments I saw that @cXoltero provide you some useful informations but some of them aren't correct. Mocha is test runner and a Chai is framework for BDD(units).

How install chai package - http://chaijs.com/guide/installation/
Guide for using assertions - http://chaijs.com/guide/styles/

KariiO
  • 9
  • 1
  • 5