leftstick / generator-es6-angular

Yeoman generator for es6 based angular skeleton
https://leftstick.github.io/generator-es6-angular
MIT License
74 stars 18 forks source link

Tests #9

Closed tiagojdf closed 8 years ago

tiagojdf commented 8 years ago

I have been trying to implement unit tests in my project to no avail. After that, I decided to go back to the first commit (what your generator created), and use gulp test. This also failed, so it seems there is some problem with your unit testing.

I keep getting the following error:

Error: [ng:areq] Argument 'HomeController' is not a function, got undefined

One thing that strikes me as odd right away is that you define var $controller; and then you use it as though it was the angular $controller.

var controller = $controller('HomeController', {
            $scope: $scope,
            $alert: {},
            HomeService: MockHomeService,
            events: {}
        });

Did you by any chance forget to use angular or angular-mocks ?

leftstick commented 8 years ago

Are you using the latest version of the generator? Since i removed all the unit test stuff in this new version.

tiagojdf commented 8 years ago

I have used your generator 27 ago, and since then the project has grown a lot, so it is impossible for me to just update the version. Do you have a change log for the past days, so I can do the same fixes in my project ? Regarding the tests, you don't use them anymore ?

leftstick commented 8 years ago

My fault, i don't have change log. What version of this generator are you using? I can install this specific version to see if i made mistake there.

I will leave ut for few versions, until i find more convenient way to write test cases.

tiagojdf commented 8 years ago

Ok, I will try to add test from my side of the project. If I manage I might make a PR

leftstick commented 8 years ago

Can you check your: test/tools/FeatureLoader.js

var loader = function(Feature) {
    var feature = new Feature();
    feature.run(); //notice here ###1
    return feature;
};

export default loader;

js/fw/lib/FeatureBase.js

import angular from 'angular';

class FeatureBase {

    constructor(name) {
        this.export = name;
        this.mod = angular.module(this.export, []);

        this.controller = this.mod.controller;
        this.factory = this.mod.factory;
        this.service = this.mod.service;
        this.directive = this.mod.directive;
        this.filter = this.mod.filter;
        this.config = this.mod.config;
        this.run = this.mod.run;
    }

    beforeStart() {
    }

    execute() { //notice here ###2
    }
}

export default FeatureBase;

I believe the issue you are encountering is, i modified the execution method name in js/fw/lib/FeatureBase.js to execute, and missed the corresponding change to test/tools/FeatureLoader.js.

And i just fixed this issue in generator-es6-angular@2.0.4, maybe you need it next time generating project

What you need to do is, open your test/tools/FeatureLoader.js, modify feature.run(); to feature.execute();