Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read attribute with the name "must" of an object if unit.js is used #6

Closed
baloghz opened this issue Dec 5, 2014 · 3 comments
Labels

Comments

@baloghz
Copy link

baloghz commented Dec 5, 2014

In the following js code the must parameter of the myObj object only appears in the console, if we not use the unit.js package (ver 0.1.8):

require("unit.js"); // delete this line and the result will be good

var myObj = {
    "parameter": "value"
};
myObj.must = "must_value";
console.log(JSON.stringify(myObj, undefined, 2));

Is it a bug, or is it a well-known feature of unit.js, which has to be taken into account when testing with it?

Thanks for the answer!

@Nicolab
Copy link
Member

Nicolab commented Dec 5, 2014

I look in the evening but you should upgrade to the last version (v1.1.0). No break in the API. your tests will not be affected.

@Nicolab
Copy link
Member

Nicolab commented Dec 6, 2014

It's not a bug, this a non enumerable property added by MustJS to be able to make assertions like
myObj.parameter.must.be.string();

To cancel it:

delete Object.prototype.must;

And it's ok

var test = require('unit.js');

delete Object.prototype.must;

var myObj = {
    'parameter': 'value'
};

console.log(JSON.stringify(myObj, undefined, 2));

Subsequently MustJS can be used in this way:

test.must(myObj.parameter).be.string();

ShouldJS done the same, so to remove the 2 monkey patches:

var test = require('unit.js');

delete Object.prototype.must;
delete Object.prototype.should;

For the nonce, I just added these details in the doc http://unitjs.com/guide/must-js.html

Thanks!

@baloghz
Copy link
Author

baloghz commented Dec 6, 2014

Thank you very much for your detailed answer!

@Nicolab Nicolab closed this as completed Dec 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants