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
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])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.