Get help with testing, discuss unit testing strategies etc.


Post by davmillar »

How can we extend our TestClass to use nested objects so we don't clutter up the test namespace? For example, we would like to use Test.Dummy.getBacon(); instead of Test.getBacon(); so we tried this based on how the mixins are structured for Siesta.Test.ExtJS:

Dummy.js
Role('TestClass.Dummy', {
  has: {
    Dummy: {
      getBacon: function () {
        window.alert("I love me some piggy bacon!!!");
      }
    }
  }
});
TestClass.js
Class('TestClass', {
  isa: Siesta.Test.ExtJS,
  does: [
    TestClass.Dummy
  ]
});
But this does not seem to work. Help?

Post by nickolay »

Hi,

If I'm correct you want to get something like:
t.dummy.getBacon()
This won't work, because methods, defined in roles are counted as methods of the class itself.

You can do the following:

1)
Role('TestClass.Dummy', {
    methods: {
        methodFromRole: function () {
            window.alert("method from role");
        }
    }
});


Class('TestClass', {
    isa: Siesta.Test.ExtJS,
    does: [
        TestClass.Dummy
    ],
    methods: {
        ownMethod: function () {
            window.alert("own method");
        }
    }
});

t.ownMethod()
t.methodFromRole()
2) Or you can create a helper class instance, which will be instantiated as "dummy" attribute:
Class('TestClass.Dummy', {
    has : {
        // reference to test
        test        : null
    },
    methods: {
        methodFromDummy: function () {
            window.alert("method from dummy");
            
            this.test.click()
        }
    }
});


Class('TestClass', {
    isa: Siesta.Test.ExtJS,
    
    has : {
        // reference to "dummy" instance
        dummy       : null
    },
    
    methods: {
        initialize : function () {
            this.dummy      = new TestClass.Dummy({ test : this }) 
            
            this.SUPER()
        },
        
        ownMethod: function () {
            window.alert("own method");
        }
    }
});

t.ownMethod()
t.dummy.methodFromDummy()

Post by davmillar »

Case 2 sounds like exactly what we need. Thank you for the quick response - I appreciate it.

Post by divyasharma »

Can you please tell me how to create these classes as we create class in ext using ext.define? and how the paths should be given?

Post by nickolay »

These classes are created outside of Ext, using the syntax provided in the examples. The files should be loaded using usual <script> tags on the harness page (do not include them in the "preload" config).

More details: https://www.bryntum.com/docs/siesta/#!/ ... test_class

See also /siesta/examples/index.html for a sample setup (custom test class is used for a "Grid" test group).

Post Reply