Ste77
Ste77

Reputation: 676

Using Chai - how to check object property contains DOM element

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

Answers (1)

T.J. Crowder
T.J. Crowder

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

Related Questions