-
16 Apr 2011 5:16 PM #1
B3 MVC Controller Unit Test Problems
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.
-
16 Apr 2011 5:31 PM #2Sencha - Community Support Team
- Join Date
- Jan 2009
- Location
- Palo Alto, California
- Posts
- 1,941
- Vote Rating
- 6
We'll include unit tests for the MVC examples, probably in the next release.
Ext JS Senior Software Architect
Personal Blog: http://edspencer.net
Twitter: http://twitter.com/edspencer
Github: http://github.com/edspencer
-
16 Apr 2011 6:15 PM #3
Sounds great thanks for the response.
-
26 Apr 2011 10:53 AM #4
So Ed what happened to those MVC unit testing examples?
-
30 Apr 2011 3:45 PM #5
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
-
15 May 2011 12:30 PM #6
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.
-
15 May 2011 4:34 PM #7
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
-
15 May 2011 9:29 PM #8
@ykey, Thank you! This gave me a clue how to get this working. In my test code I did the following:
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;-).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(); });
Of course I am not quite sure whether this controller created this way actually works but I am going to test it.
-
16 May 2011 4:25 AM #9
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:
Then you can include the jasmin files and then the rest.Code:<style> body div { display:none !important; } body .jasmine_reporter { display:block !important; } body .jasmine_reporter div { display:block !important; } </style>
With this setup only the results from the test code is shown. Anyway, it seems to work in my case.
Looks like we can't reproduce the issue or there's a problem in the test case provided.
Similar Threads
-
ExtJS Jasmine unit test reporter?
By Scott Murawski in forum Community DiscussionReplies: 4Last Post: 9 Dec 2011, 12:53 PM -
Unit test cases
By nivis1990 in forum Community DiscussionReplies: 0Last Post: 9 Mar 2011, 9:05 PM -
Unit Test
By sg707 in forum Ext: DiscussionReplies: 1Last Post: 16 Feb 2011, 1:57 PM -
Howto unit test widgets?
By KaiWeing in forum Ext GWT: DiscussionReplies: 2Last Post: 9 Aug 2010, 8:33 AM -
JS Unit Test Panel
By Ronaldo in forum Ext 2.x: User Extensions and PluginsReplies: 9Last Post: 20 Feb 2009, 9:32 AM


Reply With Quote