对于角度流星应用

时间:2016-04-10 23:49:54

标签: angularjs unit-testing meteor jasmine

所以我正在使用角度流星构建应用程序。 (Angular版本1.3.1,Meteor 1.2.1)。我正在尝试使用黑猩猩框架编写单元测试。

我在app / tests / features / login_spec.js

上有以下代码
describe('LoginController', function() {

    console.log("1");
    beforeEach(module('app'));

    console.log("2");


    var $controller;

    beforeEach(inject(function(_$controller_){
        // The injector unwraps the underscores (_) from around the parameter names when matching
        $controller = _$controller_;
    }));
    console.log("3");


    describe('$scope.login', function() {
        it('sets loggedIn to true if logs in @watch', function() {
            console.log("4");
            var $scope = {};
            var controller = $controller('LoginController', { $scope: $scope});
            $scope.email = 'user';
            $scope.password = 'password';
            expect($scope.loggedIn($scope.email, $scope.password).toEqual(true));

         });
    });
});

但是当我运行chimp --jasmine --watch时,我得到以下输出:

[chimp] Running...
1
Started



Ran 0 of 1 spec
0 specs, 0 failures
Finished in 0.003 seconds

我不知道为什么测试没有运行。有任何想法吗?

我正在关注以下教程:

https://code.angularjs.org/1.3.10/docs/guide/unit-testing

https://chimp.readme.io/docs/getting-started-jasmine

1 个答案:

答案 0 :(得分:0)

检查default Chimp configuration file:看起来Jasmine只会加载包含int gcd = 1;的文件名(当然还有support)。所以大概它不知道Angular,除非你把它配置成?

看看the accepted answer to this related question。您的规范中的功能_specmodule中定义,您需要将其与应用代码一起加载。

或者,如果您没有对Chimp进行过深度投资,那么可能值得考虑切换到Jasmine + Karma,它本身就是针对Angular的,因此大部分都是针对您的。

相关问题