Looks like we can't reproduce the issue or there's a problem in the test case provided.
  1. #1
    Sencha User ykey's Avatar
    Join Date
    Mar 2010
    Location
    USA
    Posts
    245
    Vote Rating
    27
    ykey has a spectacular aura about ykey has a spectacular aura about

      0  

    Default 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.

  2. #2
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    9
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    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

  3. #3
    Sencha User ykey's Avatar
    Join Date
    Mar 2010
    Location
    USA
    Posts
    245
    Vote Rating
    27
    ykey has a spectacular aura about ykey has a spectacular aura about

      0  

    Default


    Sounds great thanks for the response.

  4. #4
    Sencha User ykey's Avatar
    Join Date
    Mar 2010
    Location
    USA
    Posts
    245
    Vote Rating
    27
    ykey has a spectacular aura about ykey has a spectacular aura about

      0  

    Default


    So Ed what happened to those MVC unit testing examples?

  5. #5
    Sencha User ykey's Avatar
    Join Date
    Mar 2010
    Location
    USA
    Posts
    245
    Vote Rating
    27
    ykey has a spectacular aura about ykey has a spectacular aura about

      0  

    Default


    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

  6. #6
    Ext Premium Member halcwb's Avatar
    Join Date
    Mar 2010
    Location
    Rotterdam
    Posts
    379
    Vote Rating
    39
    halcwb has a spectacular aura about halcwb has a spectacular aura about

      0  

    Default 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.

  7. #7
    Sencha User ykey's Avatar
    Join Date
    Mar 2010
    Location
    USA
    Posts
    245
    Vote Rating
    27
    ykey has a spectacular aura about ykey has a spectacular aura about

      0  

    Default


    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

  8. #8
    Ext Premium Member halcwb's Avatar
    Join Date
    Mar 2010
    Location
    Rotterdam
    Posts
    379
    Vote Rating
    39
    halcwb has a spectacular aura about halcwb has a spectacular aura about

      0  

    Default


    @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.

  9. #9
    Sencha User ykey's Avatar
    Join Date
    Mar 2010
    Location
    USA
    Posts
    245
    Vote Rating
    27
    ykey has a spectacular aura about ykey has a spectacular aura about

      0  

    Default


    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.

  10. #10
    Ext Premium Member halcwb's Avatar
    Join Date
    Mar 2010
    Location
    Rotterdam
    Posts
    379
    Vote Rating
    39
    halcwb has a spectacular aura about halcwb has a spectacular aura about

      0  

    Default


    @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.

Similar Threads

  1. ExtJS Jasmine unit test reporter?
    By Scott Murawski in forum Community Discussion
    Replies: 4
    Last Post: 9 Dec 2011, 12:53 PM
  2. Unit test cases
    By nivis1990 in forum Community Discussion
    Replies: 0
    Last Post: 9 Mar 2011, 9:05 PM
  3. Unit Test
    By sg707 in forum Ext: Discussion
    Replies: 1
    Last Post: 16 Feb 2011, 1:57 PM
  4. Howto unit test widgets?
    By KaiWeing in forum Ext GWT: Discussion
    Replies: 2
    Last Post: 9 Aug 2010, 8:33 AM
  5. JS Unit Test Panel
    By Ronaldo in forum Ext 2.x: User Extensions and Plugins
    Replies: 9
    Last Post: 20 Feb 2009, 9:32 AM

Thread Participants: 5