Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Ext.create is not a function

  1. #1
    Sencha User
    Join Date
    Apr 2017
    Posts
    3
    Vote Rating
    1
      0  

    Default Ext.create is not a function

    Hi,

    I've been following the docs exactly playing around with Sencha Test. When I try to do the following I get the error seen below. Is that a bug in the docs or a bug in the actual application? I'd love if anybody could help me out quick here so I can go on .


    It seems like its not injecting the Ext global object into the test.


    node stc.js run --pool="Embedded"

    http://termbin.com/5gdx

  2. #2
    Sencha User
    Join Date
    Mar 2016
    Posts
    59
    Vote Rating
    1
      0  

    Default

    Can you include your project.json and some portion of your (or all) of your test?

    I suspect that you might be running a WebDriver Scenario and trying to use Ext.create directly. This won't work as Ext is not present in the test code context for WebDriver tests. Instead you would need to use the execute() method to execute that code "over there" in the browser that webdriver launches.

    Either that or the URL you specified in the Scenario points to a location which doesn't have Ext loaded.

  3. #3
    Sencha Premium Member vadimv's Avatar
    Join Date
    Sep 2010
    Location
    Cluj, Romania
    Posts
    794
    Vote Rating
    59
      0  

    Default

    So all the unit tests and/or the tests that need the App and Ext namespace have to be tested "In Browser" not in "WebDriver". I get for "In Browser" that the app namespace is not available:

    Code:
    describe("Unit testing MyApp.util.Utils", function () {
        var util;
    
    
        beforeAll(function (done) {
            ST.documentReady().and(function () {
                util = MyApp.util.Utils;
                done();
            })
        });
    
    
    
    
        it("should formatDocumentNumber equal", function () {
            expect(util.formatDocumentNumber('34', 'U')).toEqual('34 U');
        });
    
    
        it("should formatDocumentNumber be undefined", function () {
            expect(util.formatDocumentNumber()).toBe(undefined);
        });
    });
    
    
    // Failed with error "MyApp is not defined"
    
    
    What could be wrong here in the tests setup. I've seen the unit tests examples from sencha github, but they won't work either, I added ST.documentReady() assuming that we have to wait before the app code is available.
    Github https://github.com/vadimpopa
    Blogging @ : http://vadimpopa.com
    Twitter: @vadimvpopa

  4. #4
    Sencha User
    Join Date
    Mar 2016
    Posts
    59
    Vote Rating
    1
      0  

    Default

    Do you have Sencha CMD integration enabled in Preferences? If so then check your scenario config and ensure "Launch application" is checked. This will launch your app and should make it available.

    The alternative is to set "Launch application" to unchecked and instantiate the class directly. That might be a better option if you are unit testing your MyApp.util.Utils class in isolation. I would recommend this latter approach given the tests you have so far.

    Also, best practice for jasmine is to use the "this" reference in beforeAll/etc and it().

    You shouldn't need ST.documentReady() as Sencha Test takes care of waiting for Ext to be ready and generally should work.

    Code:
    beforeAll(function () {
      this.util = new MyApp.util.Utils();
    });
    
    it('should formatDocumentNumber equal', function () {
      expect(this.util.formatDocumentNumber('34','U')).toEqual('34 U');
    });

  5. #5
    Sencha Premium Member vadimv's Avatar
    Join Date
    Sep 2010
    Location
    Cluj, Romania
    Posts
    794
    Vote Rating
    59
      0  

    Default

    So I unchecked the Launch and unchecked Sencha Cmd also, because yes I'm writing unit tests and better to be isolated. And I fixed the test according to your suggestion. But still I'm getting the error:

    Code:
    TypeError: Cannot read property 'formatDocumentNumber' of undefined at Object.(http://127.0.0.1:8700/~orion/workspace/test/unit/util/Utils.js?_dc=1492615371227:15:20) at ST.Block.call (http://127.0.0.1:8700/~orion/files/orion.js?_dc=1492615371227:993:30) at ST.Block.invoke (http://127.0.0.1:8700/~orion/files/orion.js?_dc=1492615371227:1098:16) at Object.me.wrapperFn (http://127.0.0.1:8700/~orion/files/orion.js?_dc=1492615371227:920:16) at attemptAsync (http://127.0.0.1:8700/~orion/files/jasmine/jasmine.js?_dc=1492615371227:2942:26) at QueueRunner.run (http://127.0.0.1:8700/~orion/files/jasmine/jasmine.js?_dc=1492615371227:2890:9) at QueueRunner.execute (http://127.0.0.1:8700/~orion/files/jasmine/jasmine.js?_dc=1492615371227:2878:10) at Spec.queueRunnerFactory (http://127.0.0.1:8700/~orion/files/jasmine/jasmine.js?_dc=1492615371227:715:35) at Spec.execute (http://127.0.0.1:8700/~orion/files/jasmine/jasmine.js?_dc=1492615371227:362:10) at Object.fn (http://127.0.0.1:8700/~orion/files/jasmine/jasmine.js?_dc=1492615371227:3617:37)
    Code:
    ReferenceError: MyApp is not defined    at Object.<anonymous> (http://127.0.0.1:8700/~orion/workspace/test/unit/util/Utils.js?_dc=1492615764513:3:21)    at ST.Block.call (http://127.0.0.1:8700/~orion/files/orion.js?_dc=1492615764513:993:30)    at ST.Block.invoke (http://127.0.0.1:8700/~orion/files/orion.js?_dc=1492615764513:1098:16)    at Object.me.wrapperFn (http://127.0.0.1:8700/~orion/files/orion.js?_dc=1492615764513:920:16)    at attemptAsync (http://127.0.0.1:8700/~orion/files/jasmine/jasmine.js?_dc=1492615764513:2942:26)    at QueueRunner.run (http://127.0.0.1:8700/~orion/files/jasmine/jasmine.js?_dc=1492615764513:2890:9)    at QueueRunner.execute (http://127.0.0.1:8700/~orion/files/jasmine/jasmine.js?_dc=1492615764513:2878:10)    at queueRunnerFactory (http://127.0.0.1:8700/~orion/files/jasmine/jasmine.js?_dc=1492615764513:715:35)    at Object.fn (http://127.0.0.1:8700/~orion/files/jasmine/jasmine.js?_dc=1492615764513:3602:13)    at attemptAsync (http://127.0.0.1:8700/~orion/files/jasmine/jasmine.js?_dc=1492615764513:2942:26)

    Attachment 56182


    Attachment 56181

    Code:
            {
                "libs": [],
                "coverageFilters": [],
                "directory": "unit",
                "name": "unit",
                "profile": "classic",
                "sandbox": false,
                "globals": "*",
                "framework": "jasmine",
                "launch": false,
                "page": "http://localhost/build/testing/MyApp/index.html"
            },
    Attached Images Attached Images
    Github https://github.com/vadimpopa
    Blogging @ : http://vadimpopa.com
    Twitter: @vadimvpopa

  6. #6
    Sencha Premium Member vadimv's Avatar
    Join Date
    Sep 2010
    Location
    Cluj, Romania
    Posts
    794
    Vote Rating
    59
      0  

    Default

    I even checked back the Sencha Cmd in prefs, but getting same errors.
    Github https://github.com/vadimpopa
    Blogging @ : http://vadimpopa.com
    Twitter: @vadimvpopa

  7. #7
    Sencha User
    Join Date
    Mar 2016
    Posts
    59
    Vote Rating
    1
      0  

    Default

    Maybe can you check in your workspace for a .sencha/temp/MyApp directory and delete it completely? That is a location in which we make a special "Development Build" which should pull in all your classes and make them available. What does your Utils definition look like? You might instantiate your Utils class in a different way depending on how it is defined. I would expect something like
    Code:
    Ext.define('MyApp.util.Utils', {
      ...
    });
    and given that you should be able to

    Code:
    this.util = new MyApp.util.Utils()

  8. #8
    Sencha Premium Member vadimv's Avatar
    Join Date
    Sep 2010
    Location
    Cluj, Romania
    Posts
    794
    Vote Rating
    59
      0  

    Default

    That Utils is a singleton, but even if wouldn't be, the missing namespace error wouldn't be thrown. The tests/.sencha/temp is empty, has only the .ide folder within it, nothing more.
    Github https://github.com/vadimpopa
    Blogging @ : http://vadimpopa.com
    Twitter: @vadimvpopa

  9. #9
    Sencha User
    Join Date
    Mar 2016
    Posts
    59
    Vote Rating
    1
      0  

    Default

    When selecting a browser in the Scenario Runner a "Development Build" dialog should be shown. Agree to make that build and your classes should be available. What creates the singleton? If it is the app then you will likely need to select "Launch application" in your scenario.

    Screen Shot 2017-04-19 at 11.44.25 AM.png

  10. #10
    Sencha Premium Member vadimv's Avatar
    Join Date
    Sep 2010
    Location
    Cluj, Romania
    Posts
    794
    Vote Rating
    59
      0  

    Default

    I don't see your attachment. I don't see any Dev Build dialog. I've noticed that after I checked Launch app checkbox, the app is loaded in browser then the tests pass, then when running again they fail because the app is not loading again, checking and unchecking again may open it again....in conclusion it's a random behavior, I can't really understand how this app should be used so every time when I run the tests they pass.

    I have a gif, but this forum doesn't display it as a gif but as an image (jpg), so it's useless.
    Github https://github.com/vadimpopa
    Blogging @ : http://vadimpopa.com
    Twitter: @vadimvpopa

Page 1 of 2 12 LastLast

Similar Threads

  1. How do I create a global function
    By stay-linked in forum Sencha Architect 4.x: Q&A
    Replies: 1
    Last Post: 29 Mar 2017, 2:23 PM
  2. [FIXED] Ext.create is not a function
    By kakasab.havale in forum Bugs
    Replies: 8
    Last Post: 19 May 2016, 4:25 AM
  3. Need a function call in Ext.Create
    By nitinkalra2000 in forum Ext: Discussion
    Replies: 3
    Last Post: 7 May 2013, 9:28 PM
  4. How to create our own Ext.function in Extjs?
    By yagi in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 4 Jul 2010, 12:08 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •