Results 1 to 2 of 2

Thread: Reference Error for Sencha Test

  1. #1
    Sencha User
    Join Date
    Jun 2017
    Posts
    25
    Answers
    2

    Default Reference Error for Sencha Test

    I'm trying a simple unit test with Sencha Test but keep taking this error;


    Code:
    System error: ReferenceError: myDemoApp is not defined at Object.<anonymous> (/Users/frontend/la-nuri/Dev/Demo/MyDemoApp/test/DemoScenario/DemoSuite2.js:6:27) at Object.call (/Applications/Sencha/Test/2_1_2_1/Sencha Studio.app/Contents/Resources/app.asar/node_modules/orion-core/serve/orion.js:1101:30) at Object.invoke (/Applications/Sencha/Test/2_1_2_1/Sencha Studio.app/Contents/Resources/app.asar/node_modules/orion-core/serve/orion.js:1207:16) at Object.me.wrapperFn (/Applications/Sencha/Test/2_1_2_1/Sencha Studio.app/Contents/Resources/app.asar/node_modules/orion-core/serve/orion.js:1028:16) at attemptAsync (/Applications/Sencha/Test/2_1_2_1/Sencha Studio.app/Contents/Resources/app.asar/node_modules/orion-core/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:2942:26) at QueueRunner.run (/Applications/Sencha/Test/2_1_2_1/Sencha Studio.app/Contents/Resources/app.asar/node_modules/orion-core/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:2890:9) at QueueRunner.execute (/Applications/Sencha/Test/2_1_2_1/Sencha Studio.app/Contents/Resources/app.asar/node_modules/orion-core/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:2878:10) at Spec.queueRunnerFactory (/Applications/Sencha/Test/2_1_2_1/Sencha Studio.app/Contents/Resources/app.asar/node_modules/orion-core/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:715:35) at Spec.execute (/Applications/Sencha/Test/2_1_2_1/Sencha Studio.app/Contents/Resources/app.asar/node_modules/orion-core/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:362:10) at Object.fn (/Applications/Sencha/Test/2_1_2_1/Sencha Studio.app/Contents/Resources/app.asar/node_modules/orion-core/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:3617:37)
    I've generate a sample app with `sencha cmd` through this guide with this command;


    Code:
    sencha generate app -ext MyApp /path/to/my-app
    Here is my test suite and some other code snippets. My reference for test suite is Arthur Kay's github repo which explain unit-tests for ExtJS apps;


    Code:
     describe('Demo Suite 2', function() {
        
            describe('onConfirm() method', function() {
        
                it('should be a function', function() {
                    expect(typeof myDemoApp.view.main.MainController.onConfirm).toEqual('function');
                });
        
                it('should return a string', function() {
                    expect(typeof myDemoApp.view.main.MainController.onConfirm()).toEqual('string');
                });
            });  
        });


    This is sencha-made controller;


    Code:
     /**
         * This class is the controller for the main view for the application. It is specified as
         * the "controller" of the Main view class.
         */
        Ext.define('myDemoApp.view.main.MainController', {
            extend: 'Ext.app.ViewController',
        
            alias: 'controller.main',
        
            onItemSelected: function (sender, record) {
                Ext.Msg.confirm('Confirm', 'Are you sure?', 'onConfirm', this);
            },
        
            onConfirm: function (choice) {
                if (choice === 'yes') {
                    console.log("this is a yess")
                }
            }
        });
    I want to check `onConfirm` method with that simple unit test suite. Why cannot reach to `myDemoApp`?

  2. #2
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    London, England
    Posts
    396
    Answers
    75

    Default

    Based on the error, it looks like you may be trying to run these tests from a WebDriver scenario, so "myDemoApp" would be undefined in that context as the tests will be running separate from the browser.

    For unit tests, and in order to reference "myDemoApp", your tests need to run in-browser alongside your app code. If you edit the details of the Scenario and select "In-Browser" as the type, as opposed to "WebDriver", the tests should pass.
    Daniel Gallo

Similar Threads

  1. Replies: 1
    Last Post: 13 Jun 2017, 8:53 AM
  2. Sencha Test CLI node error
    By Artem_Ivanov in forum Q&A
    Replies: 2
    Last Post: 6 Feb 2017, 11:34 PM
  3. Replies: 1
    Last Post: 3 Feb 2017, 8:59 AM
  4. Replies: 1
    Last Post: 9 Aug 2016, 3:46 AM
  5. Replies: 2
    Last Post: 4 Aug 2016, 4:27 AM

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
  •