Hello
Good work on JSMock. I have to say, I'm not a fan of the JSUnit interface or the requirement to use the test runner which is partly why I'm writing my own. I don't any big plans to release it since the code probably doesn't follow some standards in terms of the API testing frameworks should provide. I have some pass() and fail() methods. I can make assertions. I can detect exceptions and pinpoint line numbers and I now have some basic mock functionality working. I haven't looked at the code behind JSMock too much but I'll try to work my API in a fashion that allows it.
The difference with what I'm writing an JSUnit is that my test cases are individually encapsulated into classes like SimpleTest in PHP. The reporter is a separate component just like SimpleTest too. You just run the test right from the file the test is in... heck, it even looks as simplistic as SimpleTest. I should probably seek some guidance on "standards" for the API around which to base assertions before I go too far with it in order to allow other components from other toolkits (such as JSMock) to be used.
I actually started writing the Mock objects part of the framework from scratch. It's not brilliant (at a backend level, maybe?) but I now have Full Mocks (with additional mock methods) and Partial Mocks with the usual assertions and stub features. It's not quite JSMock though

I tried to take a KISS approach (as I do with everything) and simply "inject" methods etc into a skeleton mock object which contains the features needed such as setReturnValue(), setReturnValueAt(), assertCalledNever() etc. One flaw in my design is that you need to create an instance of the mock interface before it can be mocked (because I loop over all the methods in it). I could probably works this better with hindsight and read what's on the constructor instead... I'm only a few hours in though.
For example (this test has no real meaning, it's the remnants of something I was playing with):
Code: Select all
this.testOfNothing = function()
{
//Note the need to make "new myObj()"!!
var mockFactory = new Mock(new myObj(), this);
mock = mockFactory.generate(new Array('zipButton')); //Added mock method not in real interface
mock.zipButton();
mock.assertCalledOnce('zipButton');
mock.setReturnValueAt('somethingFoo', 42, 1);
mock.setReturnValueAt('somethingFoo', 10, 2);
this.assertEqual(42, mock.somethingFoo());
this.assertEqual(10, mock.somethingFoo());
mock.assertCalledAtLeastOnce('somethingFoo');
mock.testing();
mock.assertCallCount('testing', 1);
}
Other bits and pieces I'd like in place are:
* window event capturing (e.g. if a class throws an alert() don't actually do alert() but have some fake window object catch that it was called)
* Mock events to attach to DOM nodes and then execute (i.e. a Mock mouseover event which tiggers actions like a real mouseover)
* More "correct" assertion API for scalability/portability
* As much cross browser support as possible
I'm quite a fan of keeping things as non-complex/readable as possible.
If I got it up to a certain usable stage would you want to take a look at the code from SVN and see what I would need to change to get JSMock support in it?
