Twitter Call us on +44 (0)1256 486557

Checking for presence of class in array of classes in Sencha Touch and Jasmine

When unit testing in Sencha Touch it’s sometimes a requirement to check that you’re defining the correct dependencies of a file using the ‘requires’ statement in the config.

Let’s take a controller as an example:

In our test we want to check that each of these has been required.  However, when instantiating the controller Sencha actually instantiates each of these classes and maintains a reference to them in the requires attribute of the class.  So how do we quickly and efficiently traverse them to check we have the correct files?  We can utilise the $className attribute of Sencha Touch classes and the filter method of Array in javascript.