Results 1 to 2 of 2

Thread: Scope question - It within It block?

  1. #1
    Sencha User
    Join Date
    Mar 2017
    Posts
    45

    Default Answered: Scope question - It within It block?

    I have some helper functions that contain an It block that I use to provide some more verbose output in the test results panel. The issue I'm encountering is calling a function within an it block in my test spec.

    For example, this is a textboxValidation function that is used in a switch statement. If my spec definition has a type of "text" then the switch case will run the textboxValidation function and provide the verbose output of spec.name + spec.testName from the spec definition.


    Code:
    textboxValidation: function(spec) {        // Verify defaults 
            ST.applyIf(spec, {
                inputWait: 0
            });
            it(spec.name + ': ' + spec.testName, function() {
                var target = spec.locatorFn();
                target.setValue('');
                target.type(spec.value.toString())
                    .wait(spec.inputWait)
                    .and(function(field) {
                        //Expect that the field is editable
                        if (spec.isInvalid) {
                            //Expect that the input is invalid
                            field.expect('value').toBeFalsy();
                        } else {
                            //Expect that the input is valid
                            field.expect('value').toBe(spec.value);
                        }
                        if (spec.required) {
                            //Reset required fields to their original value and assert that they are not valid
                            field.setValue('');
                            //Expect that the field is required and doesn't not accept empty value
                            field.expect('value').toBeFalsy();
                            target.type(spec.value.toString());
                        }
                    });
            });
        },
    A sample spec definition:
    Code:
    getSpecArray: function() {        return [{
                    name: 'First Name',
                    testName: 'is a required field',
                    locatorFn: stpo.Billing.firstName,
                    value: 'John',
                    required: true,
                    type: 'text'
                },
    spec.JPG

    I then call my switch case function within an It block to begin my loop and complete the form
    Code:
    FormDataEntry.enterData(specs.getSpecArray());
    A sample of the FormDataEntry switch statement that loops over my spec definition and executes the helper function based on the 'type' property defined for each spec definition:
    Code:
    FormDataEntry = {
    
        enterData: function(specs) {
            for (var i = 0; i < specs.length; i++) {
                var currentSpec = specs[i];
                console.log('current spec = ' + currentSpec.name);
                switch (currentSpec.type) {
                    case 'text':
                            WebDriverHelpers.textboxValidation(currentSpec);
                        break;
    The problem is that ST doesn't recognize the FormDataEntry.enterData(specs.getSpecArray()); function call within the It block because the textboxValidation function also contains an It block. If I comment out the It block in the textboxValidation function the FormDataEntry.enterData(specs.getSpecArray()); will execute within the It block OR I have to run the FormDataEntry.enterData(specs.getSpecArray()); outside of an It block in test case.


    So can an It be run within another It block?

  2. Jasmine does not allow nested "it" functions. Only test suites can be nested ("describe" within "describe").

    Instead, your other function can perform some additional expectations if needed, which will all show up in the results for the containing test.

    If you want to dynamically add new tests/specs (using the "it" function), this has to be evaluated before the tests commence, and can't be done after the app is being tested, e.g. this would create 5 tests:

    Code:
        describe('test', function() {
            it('test 1', function() {
                expect(1).toBe(1); 
            });
            
            for (var i = 2; i <= 5; i ++) {
                it('test ' + i, function() {
                    // do something here
                });
            }
        });

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

    Default

    Jasmine does not allow nested "it" functions. Only test suites can be nested ("describe" within "describe").

    Instead, your other function can perform some additional expectations if needed, which will all show up in the results for the containing test.

    If you want to dynamically add new tests/specs (using the "it" function), this has to be evaluated before the tests commence, and can't be done after the app is being tested, e.g. this would create 5 tests:

    Code:
        describe('test', function() {
            it('test 1', function() {
                expect(1).toBe(1); 
            });
            
            for (var i = 2; i <= 5; i ++) {
                it('test ' + i, function() {
                    // do something here
                });
            }
        });
    Daniel Gallo
    Senior Solutions Architect
    Sencha Inc.

Similar Threads

  1. Replies: 0
    Last Post: 30 Sep 2014, 5:52 AM
  2. mask() still not block keyboard - howto block it?
    By Arno.Nyhm in forum Ext GWT: Discussion
    Replies: 6
    Last Post: 19 Nov 2009, 7:28 AM
  3. Scope question (who is this?)
    By cripkd in forum Ext 3.x: Help & Discussion
    Replies: 6
    Last Post: 31 Oct 2009, 1:37 PM
  4. Scope Question
    By djfiii in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 17 Feb 2008, 6:52 PM
  5. Scope question
    By midnite_cowboy in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 29 Jan 2008, 12:58 PM

Posting Permissions

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