Skip to content

Screw-Unit javascript mocking

by Topper on July 22nd, 2008

I'll try to blog more about screw-unit javascript testing (since it's awesome!). However, I just wanted to alert everybody about my fork at github, which will let you mock out various things in your tests.

Let me know what you think.

JavaScript:
  1. //
  2. // DOM mocking
  3. //
  4. TH.insertDomMock('some_mock'); // which will insert the file dom_mocks/some_mock.html into a div
  5. //
  6. //
  7. // Object mocking
  8. var someObj = {
  9.     foo: function () { return 'bar' }
  10. };
  11. someObj.foo() == 'bar';
  12. TH.Mock.obj("someObj", {
  13.     foo: function () { return 'somethingElse' }
  14. });
  15. someObj.foo() == 'somethingElse'; // BUT!  Only for this test the next test will have a normal someObj;
  16.  
  17. //
  18. // Ajax mocking (Prototype.js only)
  19. //
  20. TH.Ajax.mock("/a_url", "someText", 200);
  21. var ajx = new Ajax.Request("/a_url", {
  22.     onComplete: function (resp) { response = resp }
  23. });
  24. expect(response.responseText).to(equal, "someText");

One Comment
  1. Mark permalink

    Screw unit kinda sucks check out jspec http://visionmedia.github.com/jspec/

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS