JMVC 3.2.4
Hello all,
I'm trying to test drive my apps with QUnit and keep tripping up with deferreds in my application code, in particular when I'm using components (mycomponent) in the render method of the application. I'm well versed with QUnit.start() and QUnit.stop(). Obviously the QUnit test runner handles async methods with start() and stop() but when I test my code the test runner fails on assertions made after deferreds because stop() and start() can't be used as the deferred is nested inside the component/app I'm instantiating.
E.g:
MyControllerTest
- test('mycontroller should instantiate `mycomponent` in the render method', function() {
- $fixture.find('div').mycontroller();
- ok($fixture.find('.mycomponent').length);
- });
MyController
- render: function() {
- this.element.html(this.view('./view.ejs');
- $this.find('div').mycomponent();
- }
Ignore the fact that this isn't the most robust test. This test will pass if there are no async methods in `mycomponent`.
If I place an async method in `mycomponent` then the headaches start because the test doesn't know when to start() even if I place stop() before the async method (because the start() would have to be nested inside the `mycomponent`...yuk!)
Has anybody come across this problem? I've got unit tests covering `mycomponent` which can run in isolation but I want to test drive the application to the point where I can test that components have instantiated and cover as much code as possible.
Is there a pattern for this? Am I doing it not goodly?!
Many thanks