Simplified Dijit Functional Testing

By on January 13, 2016 10:03 am


One of the nice features of testing with Intern and Leadfoot is the ease of authoring functional tests to mimic end-user behavior. The API for retrieving relevant DOM nodes is relatively straightforward, usually with a single line of code needed to get a reference to the relevant node.

When we started writing tests for Dijit, we realized that it was often a fair amount of boilerplate to get references to specific widget instances, attach points within those widgets, and property values of widgets. One of the advantages of Intern is you can integrate this boilerplate into a helper. So, we set out to create a simple Intern helper utility to make these operations as efficient to author as normal functional tests.

dijit-intern-helper provides a simple helper utility with three primary methods:

  • byId(widgetId): A method to retrieve a serialized reference to all methods and properties on a widget
  • getProperty(widgetId, property): Return a property value on a widget instance
  • nodeById(widgetId, attachPoint): Return a reference to a specific node within a widget instance (default is the domNode)

Note that byId is less useful for some features (such as references to DOM objects), because it is simply a serialization of items from the browser back to the Node.js Intern test runner. So we more commonly use getProperty and nodeById. Here is an example of how a test might look without this utility:

.executeAsync(function (done) {
	require(['dijit/registry'], function (registry) {
.then(function (node, setContext) {

And with the dijit-intern-helper, the reference to the relevant node can be reduced to this:

.then(dijit.nodeById('titlePane', 'titleBarNode'))

There are times where it is sufficient to just use normal DOM querying methods provided by Intern, but in cases where you want to operate on a specific widget instance, we find that this utility can reduce the complexity of your tests (and make them easier to read). We find this is especially powerful when combined with the page object pattern.


To use dijit-intern-helper, simply grab the source code and then within your tests, simply add the dependency to dijit-intern-helper within your define depedencies:

    'intern!object', 'intern/chai!assert', 'require',
], function (registerSuite, assert, require, dijit, pollUntil) {

Learning more

To learn more about testing with Intern and Dijit, we offer Dojo 202 and Intern workshops. We are also happy to help you with your efforts to improve your tests and code quality via our JavaScript support services. Finally, if you want to discuss how we can help you implement a better approach to testing your applications, please contact us for an initial consultation.


  • guest

    Is there a way in leadfoot or the dijit-intern-helper to search by any element tag? with dynamically created items, ui based functional testing best lends itself to static identifiers whether it be an element id, or some other tag that’s static, no matter the configuration.

  • There are ways within leadfoot to get a reference to an element, but it’s not entirely clear what you are asking by “search by any element tag”. Meaning any div for example? There’s and of course you can find anything by various xpath expressions. The main idea with dijit-intern-helper is that you essentially know the structure of your app (meaning ids are non-transitory for top level UI components).