xolvio / rtd

DEPRECATED: The Test Runner for Meteor
164 stars 37 forks source link

RouteController stub and .extend() #162

Closed tixpaul closed 10 years ago

tixpaul commented 10 years ago

Just (finally) got rid of all my phantomjs errors when running ./rtd --debug

One thing that had me stuck for quite some time was the RouteController stub in iron-router-stubs.js. The issue happens when using .extend() on a controller from RouteController.extend();

In my case:

ArticleListController = RouteController.extend({...});

TopicListController = ArticleListController.extend({...});

Results in an undefined function issue for ArticleListController.

The way I got it working was to override the provided stub with:

var RouteControllerClass = function(route){
    //apply properties of route to controller so you can test against them later
    for(var i in route){
        this[i] = route[i];
    }
};

RouteControllerClass.prototype = {
    extend: function(route) {
        return new RouteControllerClass(route);
    }
};

var RouteController = new RouteControllerClass();

There's probably a much tidier way of doing this but it caused me quite a headache so I thought I'd open the issue with a workaround for anyone stuck on the same thing.

samhatoum commented 10 years ago

That's a great way to do it, and I've actually modified the iron-router stub to do exactly that. Thanks :)