gulp-jasmine给出了TypeError

时间:2014-11-18 22:46:49

标签: javascript angularjs unit-testing jasmine gulp

我开始尝试使用测试项目学习javascript单元测试。 该项目的根目录有一个gulpfile.js,其中包含: 'use strict';

var gulp = require('gulp');
var plugins = require('gulp-load-plugins')({
     config: {
         'dependencies': {
             'gulp-jasmine': '*'
          }
     },
     camelize: true
});
gulp.task('jstest', function() {
    return gulp.src(['js_unit_tests/*'])
        .pipe(plugins.jasmine({ verbose: true, showStackTrace: true }));
});

js_unit_tests目录中唯一的文件是grid-tests.js,它看起来像这样:

///<reference path="../Scripts/jasmine/jasmine.js" />
///<reference path="../Scripts/angular.js" />
///<reference path="../Scripts/angular-mocks.js" />
///<reference path="../Scripts/underscore.js" />
///<reference path="../app.js" />
///<reference path="../Scripts/Components/Grid/grid.js" />

describe('GridController Test', function () {
    beforeEach(module('app'));

    describe('GridCtrl', function () {
        var scope,
            controller,
            timeout;

        beforeEach(inject(function ($rootScope, $controller, $timeout) {
            scope = $rootScope.$new();
            controller = $controller;
            timeout = $timeout;
        }));

        it('should initialize vm values without scope isolate properties being provided', function () {
            var cont = controller('GridCtrl', { $scope: scope, $timeout: timeout });

            expect(scope.actions).toBeUndefined();
            expect(scope.data).toBeUndefined();
            expect(scope.settings).toBeUndefined();

            expect(cont.actions instanceof Array).toBeTruthy();
            expect(typeof (cont.data)).toBe('object');
            expect(typeof (cont.settings)).toBe('object');
            expect(cont.gridActions instanceof Array).toBeTruthy();
            expect(cont.columnDefinitions instanceof Array).toBeTruthy();
            expect(cont.rows instanceof Array).toBeTruthy();
            expect(cont.selectedColumnDefinitionId).toBe('');
            expect(cont.selectedRowId).toBe(0);
            expect(typeof (cont.onclick)).toBe('function');
            expect(typeof (cont.onblur)).toBe('function');
            expect(cont.sortedColumn).toBe('');
            expect(cont.sortDirection).toBe('none');
            expect(typeof (cont.sort)).toBe('function');
        });
    });
});

所有测试都使用resharper运行并通过。执行上面的gulp任务虽然给了我这个:

<dir>\Experiment\AngularUIComponents\AngularUIComponents>gulp
 jstest
[16:40:43] Using gulpfile ~\Desktop\a\Experiment\AngularUIComponents\AngularUICo
mponents\gulpfile.js
[16:40:43] Starting 'jstest'...
Running 1 specs.

GridController Test
    encountered a declaration exception: failed

Failures:
1) GridController Test encountered a declaration exception
1.1) TypeError: object is not a function

1 spec, 1 failure
Finished in 0.008 seconds
[16:40:43] 'jstest' errored after 62 ms
[16:40:43] Error in plugin 'gulp-jasmine'
Message:
    Tests failed

我无法弄清楚我的配置不当。任何帮助将不胜感激。

0 个答案:

没有答案