0

I maintain a custom library consisting of many dijit widgets at the company I work at.

Many of the defects/bugs I have had to deal with were the result of this.inherited(arguments) calls missing from overriden methods such as destroy startup and postCreate.

Some of these go unnoticed easily and are not always discovered until much later.

I suspect I can use dojo\aspect.after to hook onto the 'base' implementation, but I am not sure how to acquire a handle to the _widgetBase method itself.

Merely using .after on the method of my own widget would be pointless, since that wouldn't check whether this.inherited(..) was inded called.

How can I write a generic test function that can be passed any dijit/_WidgetBase instance and checks whether the _widgetBase's methods mentioned above are called from the widget when the same method is called on the subclassing widget itself?

Bottom-line is how do I acquire a reference to the base-implementation of the functions mentioned above?

Joeppie
  • 438
  • 3
  • 16

2 Answers2

0

After reading through dojo's documentation, declare.js code, debugging, googling, debugging and hacking I end up with this piece of code to acquire a handle to a base method of the last inherited class/mix-in, but I am not entirely happy with the hackiness involved in calling getInherited:

Edit 2 I substituted the second param of getInherited with an empty array. While I actually get a reference to the method of the baseclass using aspect doesn't work. It appears this approach is a bust.

require(['dijit/registry','dojo/_base/declare','mycompany/widgets/widgetToTest'],
function(registry,declare,widgetToTest)
    {

      var widget = registry.byId('widgetToTestId');
      var baseStartup = getBaseMethod(widget,'startup');

      function getBaseMethod(widget,methodName){
        return widget.getInherited(methodName,[]);
      }

      //This is the method body I want to use .after on to see if it was called, it returns the last overriden class in the array of inherited classes. (a mixin in this case, good enough for me!)
      alert(baseStartup);

    });
Joeppie
  • 438
  • 3
  • 16
0

I have given up trying to use dojo/aspect.

I have instead opted to modify the code of our custom base widget to incorporate snippets such as the one below. They are automatically removed when creating a release-build in which console-calls and their content are removed:

console.log( 
        function(){
            (this._debugInfo = this._debugInfo|| {}).postCreate=true;
        }.call(this)  
    );

A simple method in boilerplate code I added near the unittests is available so that I can call it on all mycompany.widgets.basewidget instances in their respective unittests.

Joeppie
  • 438
  • 3
  • 16