Chai: expect(undefined).to.be.defined behaving unexpectedly

Created on 11 Apr 2017  路  2Comments  路  Source: chaijs/chai

This seems to be such an obvious bug that I feel like I'm missing something but I was following the typical "red-green-refactor" cycle of TDD and stumbled across a scenario where expect(undefined).to.be.defined was allowing a test to pass when used with Mocha. I've got a repo at https://github.com/mchandleraz/chai-wat that shows the issue.

I would expect a function that does not return anything to cause the 2nd test to fail (as the 3rd test does). Instead, only the 3rd test in my repo fails.

Have I found a bug, or is this expected?

Thanks!

Most helpful comment

Up until ES6 proxies, there was no way for Chai or Mocha to know that a non-existent property such as defined was chained off of an existing property like be. This problem is fixed in Chai v4 in ES6 compatible environments, currently available on npm via chai@canary. This and related issues are discussed in length in #726. Gonna close this issue due to duplication but please feel free to discuss in that thread.

All 2 comments

Up until ES6 proxies, there was no way for Chai or Mocha to know that a non-existent property such as defined was chained off of an existing property like be. This problem is fixed in Chai v4 in ES6 compatible environments, currently available on npm via chai@canary. This and related issues are discussed in length in #726. Gonna close this issue due to duplication but please feel free to discuss in that thread.

Thanks @meeber, I figured I was missing something.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

qbolec picture qbolec  路  5Comments

ghost picture ghost  路  4Comments

zzzgit picture zzzgit  路  3Comments

andipavllo picture andipavllo  路  3Comments

JuHwon picture JuHwon  路  5Comments