test2.html 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <html>
  2. <head>
  3. <script language="javascript">
  4. function button_onclick () {
  5. el = document.getElementById ('text');
  6. el.innerHTML = "you clicked me!";
  7. }
  8. </script>
  9. </head>
  10. <body>
  11. <span id="text">you haven't clicked me...</span><br/>
  12. <button id="button" onClick="javascript:button_onclick()">Click me!</button>
  13. <!-- the test for the above html -->
  14. <script language="javascript">
  15. var TestFixture = {
  16. test_button: function() {
  17. JSUnit_BindElement ("text");
  18. Assert.NotNull ("JSUnit_GetElement()", "text element exists");
  19. Assert.NotNull ("JSUnit_GetElement('button')", "button element exists");
  20. Assert.AreEqual ("you haven't clicked me...", "JSUnit_GetElement().innerHTML", "initial text");
  21. var button = JSUnit_GetElement ("button");
  22. JSUnit_Click(button);
  23. /* it's okay to put stuff after this JSUnit_Click call since
  24. * we didn't call JSUnit_TestCausesPageLoad */
  25. Assert.AreEqual ("you clicked me!", "JSUnit_GetElement().innerHTML", "text after button click");
  26. }
  27. };
  28. </script>
  29. </body>
  30. </html>