Gotchas with Hapi's Code Library

2015-07-22 10:06:32 -0400

Overall, I've had a good experience with HapiJS and Code, Hapi's assertion library. There was one gotcha with Code's deep.equal function. If you are comparing two objects that have identical non-function properties, but different function properties, deep.equal will fail. So, for example, if you compare a Hapi response to a Plain Old Javascript Object fixture, you will get an exception.

The solution is to strip the non-function properties before comparing:

// response - an object with some function properties
// fixture - a Plain Old Javascript Object
var responsePojo = JSON.parse(JSON.stringify(response));