Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In my Javascript Unit test, expect(true).toBeTruthy() fails

I do not understand how this is possible. I got this test from an example and it seems impossible for it to be failing, but it is:

expect(true).toBeTruthy();

.

PhantomJS 2.1.1 (Windows 7 0.0.0) Controller:TrivialCtrl should be truthy FAILED
    undefined is not a constructor (evaluating 'expect(true).toBeTruthy()')
    c:/Users/Donald/workspace/karma-trivial/spec.js:25:28

This is Karma with Chai, Mocha, and PhantomJS

like image 328
Don Subert Avatar asked Oct 14 '25 14:10

Don Subert


1 Answers

The expect function is typically used with the chai assertion library: have you loaded this plugin?

You need to:

npm install chai karma-chai --save-dev

And add karma-chai to your list of plugins.

Additionally, reviewing the chai docs, I'm not sure if toBeTruthy is an operator: http://chaijs.com/api/bdd/.

You can however use ok:

expect(true).to.be.ok

like image 120
Calvin Belden Avatar answered Oct 17 '25 02:10

Calvin Belden



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!