From 88306eb12ba54f1e7da007b40af3eef5b30e7853 Mon Sep 17 00:00:00 2001 From: Juliusz Gonera Date: Wed, 30 Nov 2011 17:55:51 +0100 Subject: [PATCH] a workaround for a weird behavior of converting primitives to objects in JavaScriptCore --- lib/should.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/should.js b/lib/should.js index bb692c8..1a4ebfc 100644 --- a/lib/should.js +++ b/lib/should.js @@ -78,6 +78,14 @@ exports.not.exist = function(obj, msg){ Object.defineProperty(Object.prototype, 'should', { set: function(){}, get: function(){ + // this is needed in JavaScriptCore, if not applied, primitives are + // converted to objects which results in weird stuff, e.g. + // AssertionError: expected { '0': 't', '1': 'e', '2': 's', '3': 't' } to equal 'test' + if (this instanceof String || this instanceof Number) { + return new assert.Assertion(this.constructor(this)); + } else if (this instanceof Boolean) { + return new assert.Assertion(this == true); + } return new Assertion(this); }, configurable: true