Picture of Chris Jones
Component unit tests
by Chris Jones - Thursday, 16 January 2014, 12:10 PM
 

Currently testing a plugin in isolation is difficult, because you can't reference the framework and plugins don't work on their own.

I'd like to look for peoples input on what the best solution would be.

My ideas are:-

1) Fake the framework. Assuming the plugin only requires ComponentView or QuestionView and Adapt, we can set up the requirejs config to use dummy objects instead. sinon.js will create stub methods that you can use to assert whether they were called correctly too. The down side is that this won't protect from changes to the framework that may break a plugin.

2) Use the actual framework Include the framework as a dependency. Not sure on how to do this gracefully, git submodules are a bit flakey imo, npm package is more maintenance but we can depend on a specific version in the component.

 

 

 

 

Picture of Daryl Hedley
Re: Component unit tests
by Daryl Hedley - Thursday, 16 January 2014, 1:09 PM
 

Thanks for this Chris.

It raises some interesting questions because components inherit from ComponentView, which needs AdaptView. AdaptView has Backbone, Handlebars and Adapt as dependencies. Backbone has an Underscore dependency.

This means we have a lot of dependencies on the core for testing. I wonder if there's a way we can pull down the latest version of the master branch and add it in.

I'd quite like to know if anyone has come across an issue like this before.

Thanks,

Daryl

Picture of Chris Jones
Re: Component unit tests
by Chris Jones - Thursday, 16 January 2014, 2:18 PM
 

A faked ComponentView would look a bit like

{

        initialize: function() {},

        preRender: function() {},
        
        postRender: function() {},
        
        render: function() {},
 
        addChildren: function() {}.
}      
 
Just enough to get the test to run.