Looks like we can't reproduce the issue or there's a problem in the test case provided.
-
B3 MVC Controller Unit Test Problems
I am having one hell of a time getting a simple Jasmine unit test to run for one of my controllers because of its dependency on Ext.app.Application. I am getting one error after another from the Loader even after overriding the bindReady function in Ext.app.Application. I really think an example of some simple unit tests needs to be included in the final release.
-
We'll include unit tests for the MVC examples, probably in the next release.
-
Sounds great thanks for the response.
-
So Ed what happened to those MVC unit testing examples?
-
Still very much looking for help with this. MVC in Sencha Touch includes hooks to disable automatic application loading which is required to enable unit testing of controller classes. I do not see the same hooks when browsing the source for MVC in ExtJS 4.
Ext.app.Controller: line 189
Code:
TypeError: Cannot call method 'getModel' of undefined
-
TypeError: Cannot call method 'getModel' of undefined
I run into the same problem. I like to write some unit tests for my controllers using Jasmine. However I cannot create a controller using Ext.create because of the TypeError: Cannot call method 'getModel' of undefined.
I browsed the svn source code but could not find how to handle this. However, I would very much appreciate to be able to write unit test. By the way, at the moment I am using the latest production code for ExtJs 4.0.
-
Halcwb - I have still not gotten this to work yet.
I can only hope that the development team is still looking at this. As far as I can tell the MVC framework is not unit testable in its current form. It is also not possible to developing a controller in isolation without adding it to an Ext.app.Application first.
I posted this in another thread. It illustrates the coupling in the app package.
http://butunclebob.com/ArticleS.Mich...uleOfApiDesign
-
@ykey, Thank you! This gave me a clue how to get this working. In my test code I did the following:
Code:
createProductController = function () {
return Ext.create('GenForm.controller.product.ProductController', {
application: GenForm.application
});
};
it('can be created', function () {
console.log(createProductController());
expect(createProductController()).toBeDefined();
});
it('should have a saveProduct function', function () {
expect(createProductController().saveProduct).toBeDefined();
});
I just passed the reference of the parent application to the application property of the controller. Now the first test passes. The second test fails, but this was ment to fail, I would like to write the test, then I write the code;-).
Of course I am not quite sure whether this controller created this way actually works but I am going to test it.
-
Halcwb - I didn't get very far going down that road. You will have more luck if you disable automatic Viewport creation and override your applications launch function in the unit test. Otherwise your Viewport will load. Either way all of your other controllers will still load because there is no hook to prevent this (well that I could find).
I think it is worth mentioning what it is I want to test. Basically I want to be able to regression test my refs and control statements. Any other logic can be moved to an easier to test class and any business logic should be moved to the server. I don't want to render UI components for these unit tests if I can avoid it. Selenium can be used for that kind of integration level test.
-
16 May 2011, 12:05 PM
#10
@ykey. I am sorry, I should have mentioned that I am using jasmine. In the index file for the tests you can put the below snippet of code:
Code:
<style>
body div
{
display:none !important;
}
body .jasmine_reporter
{
display:block !important;
}
body .jasmine_reporter div
{
display:block !important;
}
</style>
Then you can include the jasmin files and then the rest.
With this setup only the results from the test code is shown. Anyway, it seems to work in my case.