Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Can JSTestDriver be used to test DOM behaviors and interactions?

I see I can write tests to exercise pure JS but how do I go about testing against HTML or DOM?

Can I deliver with each test HTML for browsers to render and the tests to run against?

share|improve this question
    
I always found JSTestDriver quite inconvenient when it comes to test JavaScript constructs that slightly interact with the DOM. I switched to QUnit in that case. –  Juri Mar 19 '12 at 14:50
add comment

2 Answers 2

up vote 0 down vote accepted

Try using the Html Doc feature...

You should be able to do stuff like:

    /*:DOC += 
    <div id="page">
       <div id="foo">yyy</div>
       <div class="bar">
           <p>xxxx</p>
       </div>
       <div>hilo!</div>
    </div>
    */ 

...inside your tests, and JSTestDriver will inject that stuff into the DOM. Of course, if you're talking about injecting entire complete pages into your test, this might not be that great an option. Having said that, testing your code against small pieces of DOM like this is probably going to give you better isolation.

share|improve this answer
add comment

I tend to use selenium. It lets you drive a browser and interact with the page. It can be quite useful for this kind of testing.

It does have some limits, You can do a lot of does element exist, if so click it. But its not so easy to check if it is visible, and not off screen or buried or the like

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.