I have an object like this:
var obj = {
"uuid": "60afc3fa-920d-11e5-bd17-b9db323e7d51",
"type": "candy"
}
I want to write a test that first checks that the object has the โuuidโ property first, and then โuuidโ is a specific length (36 characters).
Trying this does not work
obj.should.have.property('uuid').which.should.have.length(36)
Failure:
Uncaught AssertionError: expected Assertion {
obj: '60afc3fa-920d-11e5-bd17-b9db323e7d51',
params: { operator: 'to have property \'uuid\'' },
negate: false } to have property 'length' of 36 (got [Function])
And this (which does not actually make syntactical meaning anyway), since it applies to the parent object, not the value)
obj.should.have.property('uuid').and.be.length(36)
Failure:
Uncaught TypeError: usergridResponse.entity.should.have.property(...).which.should.be.equal.to is not a function
Even this does not work:
obj.should.have.property('uuid').which.equals('60afc3fa-920d-11e5-bd17-b9db323e7d51')
So, what is the correct way to associate statements about a property of an object?
source
share