Tag: jasmine

让Jasmine在服务器端运行

我正在尝试开始使用Node.JS在服务器端testingJavaScript 我正在使用grunt和grunt-jasmine-node ,但我无法运行我的testing。 它只是logging PS C:\ Development \ NET \ Source \ jsn> grunt运行“jasmine_node”任务未定义 在0.001秒内完成0个testing,0个断言,0个失败 完成,没有错误。 这是我的Gruntfile.js module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), jasmine_node: { specNameMatcher: 'spec', projectRoot: '.', requirejs: false, forceExit: true, jUnit: { report: false, savePath : "./build/reports/jasmine/", useDotNotation: true, consolidate: true } } }); grunt.loadNpmTasks('grunt-jasmine-node'); grunt.registerTask('default', 'jasmine_node'); }; 而我的文件结构是这样的: 那么,我做错了什么? 这就像stub.js文件甚至没有加载,因为它有一个console.log调用来testing。

如何存根要求()/期望调用模块的“根”function?

考虑下面的茉莉花规格: describe("something.act()", function() { it("calls some function of my module", function() { var mod = require('my_module'); spyOn(mod, "someFunction"); something.act(); expect(mod.someFunction).toHaveBeenCalled(); }); }); 这工作得很好。 像这样的东西使它变成绿色: something.act = function() { require('my_module').someFunction(); }; 现在看看这个: describe("something.act()", function() { it("calls the 'root' function of my module", function() { var mod = require('my_module'); spyOn(mod); // jasmine needs a property name // […]

咕噜茉莉节点testing运行两次

我设置了grunt来运行node.js茉莉花testing。 出于某种原因,使用此configuration,结果总是显示双倍的testing。 这是我的configuration: 我正在使用插入grunt的茉莉花节点 。 /spec/some-spec.js : var myModule = require('../src/myModule.js'); describe('test', function(){ it('works', function(done){ setTimeout(function(){ expect(1).toBe(1); done(); }, 100); }); }); Gruntfile.js : module.exports = function(grunt) { grunt.initConfig({ jasmine_node: { options: { forceExit: true }, all: ['spec/'] } }); grunt.loadNpmTasks('grunt-jasmine-node'); grunt.registerTask('default', ['jasmine_node']); }; 这导致两个testing运行,而不是一个。 > grunt Running "jasmine_node:all" (jasmine_node) task .. Finished in 0.216 […]

如何用茉莉花和browserify进行unit testing?

任何最好的方式来运行浏览器风格的代码茉莉花HTML记者? 我也希望能够用phantomjs来运行这个headless,因此需要HTML记者。

如何使用Jasmine 2.3和SuperTesttestingExpress.js路由

我使用通过NPM安装的Jasmine 2.3 ,并使用Grunt执行。 'use strict'; module.exports = function(grunt) { grunt.initConfig({ package: grunt.file.readJSON('package.json'), exec: { jasmine: 'node_modules/.bin/jasmine' } }); require('load-grunt-tasks')(grunt); require('time-grunt')(grunt); grunt.registerTask('default', 'exec:jasmine'); }; 我导出了一个Express.js应用程序对象,并将其与SuperTest一起用于我的规范中。 'use strict'; var supertest = require('supertest') var application = require('../../../../../server'); describe('GET /api/users', function() { it('should respond with json', function(done) { supertest(application) .get('/api/users') .set('Accept', 'application/json') .expect('Content-Type', /json/) .expect(200, done); }); }); 当我运行规范时,即使预计有200状态码, […]

PhantomJS退出意外退出代码-1073741819

我在Windows 7 PC上用PhantomJS(通过Grunt)运行一些Jasmine规格,而且碰巧遇到以下错误: Testing jasmine specs via phantom …… Running PhantomJS…ERROR >> 0 [ '' ] Warning: PhantomJS exited unexpectedly with exit code -1073741819. Use –force to continue. Aborted due to warnings. 如果我删除一堆testing,错误不会出现; 但是我不知道是什么原因导致错误。 我也觉得奇怪,它只是偶尔发生。 任何想法为什么发生这种情况

如何debugging从Visual Studio代码中的Grunt运行茉莉花testing?

我的unit testing是通过Grunt使用Karma / Jasmine运行的。 当我跑步 grunt test testing从命令行执行。 在Visual Studio代码中打开项目时,可以使用“ Tasks: Run Test Task相同的命令。 VSCode使用test参数执行Grunt并显示输出。 在这种情况下,如何debugging由VSCode运行的testing用例? 当我按下F5时 , launch.json模板文件被打开。 我需要提供什么program , args等来启动/debugging通过grunt test运行相同的grunt test ? 我已经尝试了以下内容: program : /usr/local/bin/grunt args : ["test"] 这成功地启动了Grunt进程并且执行了testing,但是它并不停止在我的testing代码的断点处。 除此之外,它会在几秒钟后closures(或崩溃)整个VSCode进程。 不知道这是VSCode中的错误还是上述运行configuration的结果。

检测不需要的function(fdescribe,describe.only)作为Gulp任务

如何在Node中检测代码库中不需要的函数的使用,特别是Gulp? 我正在检查无意中损坏的规格,即ddescribe / fdescribe和iit / fit茉莉花或.only和.skip为摩卡: // should be reported fdescribe(function () { // should not be reported it(function () { var fit = …; this.fit = …; }); // should not be reported // fit(function () { … }); // should be reported xit(function () { … }); // should be reported fit(function () […]