Results 1 to 10 of 10

Thread: System error: ReferenceError: require is not defined at Object.beforeEach

  1. #1
    Sencha Premium User
    Join Date
    Sep 2010
    Location
    UK
    Posts
    134

    Default System error: ReferenceError: require is not defined at Object.beforeEach

    Hiya,

    I try to use module.exports and require but it seems I can't get it work. I have tried something like that

    PHP Code:
    describe("Login", () => {
        
    beforeEach(() => {
        
    // Capture any XHR responses    
        
    var common = require('./lib/common');    
        var 
    me this;    
        
    me.responses = [];    
        
    common.setupCapture(me.responses);            
        
    Ext.util.Cookies.clear('sid');        
        
    // Wait for the login screen        
        
    ST.component('#username'2000);    }); 
    I have tried both ./lib/ and ../lib, still got the same require reference error.

    There is not much different between my Sencha Test to the one in https://www.sencha.com/blog/sencha-t...lly-available/,

    screen.png
    Thanks
    Joe

  2. #2
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    Redwood City, CA
    Posts
    325
    Answers
    49

    Default

    Try specifying the file extension, e.g.

    Code:
    var common = require('./lib/common.js');
    Daniel Gallo
    Senior Solutions Architect
    Sencha Inc.

  3. #3
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    Redwood City, CA
    Posts
    325
    Answers
    49

    Default

    Actually, I just noticed you have an In-Browser scenario - "require" can only be used in WebDriver scenarios.

    By default, any files in the "lib" folder will get included in the In-Browser test run.
    Daniel Gallo
    Senior Solutions Architect
    Sencha Inc.

  4. #4
    Sencha Premium User
    Join Date
    Sep 2010
    Location
    UK
    Posts
    134

    Default

    I have tried just calling the function (like setupCapture(...) ) and calling the module base function name (like common.setupCapture(...) ). Both still come back with ReferenceError, not defined in beforeEach.

  5. #5
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    Redwood City, CA
    Posts
    325
    Answers
    49

    Default

    Have you changed the scenario type to WebDriver?

    If so, can you share the content of common.js?
    Daniel Gallo
    Senior Solutions Architect
    Sencha Inc.

  6. #6
    Sencha Premium User
    Join Date
    Sep 2010
    Location
    UK
    Posts
    134

    Default

    Ok, I'm one step further. After changing to Web-Driver and fixing some syntax errors, my test can do require('./lib/common.js').

    However, it reports with an error: TypeError: Cannot read property 'on' of undefined at Object.setupCapture in common.js which is referring to Ext.Ajax.on.

    Here is the code:

    function setupCapture(responses) {
    // Listen for all Ajax responses
    Ext.Ajax.on('requestcomplete', function(connection, response, options) {
    responses.push({
    url: options.url,
    response: JSON.parse(response.responseText)
    });
    });
    }

    It looks like the ExtJs library not loaded.

  7. #7
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    Redwood City, CA
    Posts
    325
    Answers
    49

    Default

    This is because the tests are running separately (in isolation) from the browser, so "Ext" is undefined. If you are needing to reference Ext JS APIs, you'll need to keep the scenario type as In-Browser, and not use "require". Instead, in your lib file, just define a JS class / object as you would do normally, and that lib file will automatically be included in the browser during a test run, so the equivalent of "require" isn't needed.
    Daniel Gallo
    Senior Solutions Architect
    Sencha Inc.

  8. #8
    Sencha Premium User
    Join Date
    Sep 2010
    Location
    UK
    Posts
    134

    Default

    Understood. Sorry for the misunderstanding.

  9. #9
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    Redwood City, CA
    Posts
    325
    Answers
    49

    Default

    Sure, no problem.
    Daniel Gallo
    Senior Solutions Architect
    Sencha Inc.

  10. #10
    Sencha Premium User
    Join Date
    Sep 2010
    Location
    UK
    Posts
    134

    Default

    FYI, for in-browser testing. The Sencha Test does't simply include js files in the lib directory.

    I have to manually specify in the test dialog box.

    screen.png

    It took me a few tries to figure it out that the root directory for Additional Libraries is the project directory, not under 'test' or 'test/unit'.

    Joe

Similar Threads

  1. Replies: 2
    Last Post: 17 Jun 2014, 11:34 PM
  2. ReferenceError: calculates is not defined. Error in ExtJS 2.3
    By arunmatics in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 28 Jan 2014, 2:52 PM
  3. ReferenceError: calculates is not defined. Error in ExtJS 2.3
    By arunmatics in forum Ext GWT: Bugs (2.x)
    Replies: 0
    Last Post: 17 Jan 2014, 11:26 AM
  4. ReferenceError: calculates is not defined. Error in ExtJS 2.3
    By arunmatics in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 17 Jan 2014, 11:26 AM
  5. Replies: 0
    Last Post: 17 Jan 2014, 11:24 AM

Posting Permissions

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