Reputation: 676
How can I test that an object property contains the value of a DOM element in Chai, eg:
someObject = function(){
element: $('#foo');
}
How do I check that element equals the jquery object $('#foo')?
So far, I have tried:
someObject.should.have.property('element', $('#foo')
someObject.should.have.property('element').with.value($('#foo'))
But these fail.
Anyone have any ideas? ( Setup - Requirejs, Mocha, Chai )
Thanks
Upvotes: 3
Views: 1547
Reputation: 1074335
Every time you call $()
, you get back a new object wrapping the matched elements (if any). To access the actual DOM element in your example, you need to use [0]
(since in your example, there will be only one matched element or none).
Something along the lines of:
someObject.should.have.deep.property('element[0]', $('#foo')[0])
Upvotes: 2