Javascript 大口喝茉莉花会引起打字错误
我已经开始尝试通过一个测试项目学习javascript单元测试。 项目根目录下有一个gulpfile.js,其中包含以下内容: "严格使用",Javascript 大口喝茉莉花会引起打字错误,javascript,angularjs,unit-testing,jasmine,gulp,Javascript,Angularjs,Unit Testing,Jasmine,Gulp,我已经开始尝试通过一个测试项目学习javascript单元测试。 项目根目录下有一个gulpfile.js,其中包含以下内容: "严格使用", var gulp = require('gulp'); var plugins = require('gulp-load-plugins')({ config: { 'dependencies': { 'gulp-jasmine': '*' } }, camel
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');
});
});
});
///
///
///
///
///
///
描述('GridController测试',功能(){
在每个(模块(“应用”)之前;
描述('GridCtrl',函数(){
var范围,
控制器,
超时;
beforeach(注入函数($rootScope、$controller、$timeout){
scope=$rootScope.$new();
控制器=$controller;
超时=$timeout;
}));
它('应该在不提供范围隔离属性的情况下初始化vm值',函数(){
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.)为(“”);
expect(cont.sortDirection).toBe('none');
expect(typeof(cont.sort)).toBe('function');
});
});
});
所有测试都使用resharper运行并通过。但执行上述“吞咽”任务会给我带来以下好处:
<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
\Experiment\AngularUIComponents\AngularUIComponents>gulp
jstest
[16:40:43]使用gulpfile~\Desktop\a\Experience\AngularUIComponents\AngularUICo
组件\gulpfile.js
[16:40:43]正在启动“jstest”。。。
运行1个规格。
网格控制器测试
遇到声明异常:失败
失败:
1) GridController测试遇到声明异常
1.1)TypeError:对象不是函数
1个规格,1个故障
在0.008秒内完成
[16:40:43]“jstest”在62毫秒后出错
[16:40:43]插件“gulp jasmine”中出现错误
信息:
测试失败
我搞不清楚我配置了什么。任何帮助都将不胜感激。您是否找到了导致这种情况的原因?