1

I am using Chai with should. Works great. However when I try to work with an object that has a property named should I run into trouble:

// object under test
function run() {
    var x = {};
    console.log('typeof should:', typeof(x.should)); // 'object'

    if (x.should == null) {
        console.log('initializing x.should');
        x.should = [];
    }

    // TypeError: Object #<Assertion> has no method 'push';
    x.should.push('foobar')
}

// test code
var chai = require('chai');
chai.should();
run();

When I run this code with Mocha, the condition is never true and hence the property should is never initialized.

Since the problem arises in an included library (elastic.js to be precise) modifying the object under test is not an option.

Is there any way I can still use Chai's should?

Philipp Jardas
  • 3,222
  • 3
  • 29
  • 42

0 Answers0