Tag: jasmine

编写async.parallel的testing。

我是javascript的新手。我正在尝试使用proxyquire编写基本的unit testing。 下面的代码。 文件 – 答: const modA=require('./modA'); const modB=require('./modB'); const async=require('async'); module.exports=function(a,b,callback){ async.parallel([ function(callback){ // db call modA(a,b,callback); }, function(callback){ // db call mobB(a,b,callback); } ], //not able to test code (err,res){ //do something }); }; 文件A的unit testing如下所示: const proxyquire=require('proxyquire'); function modaAStub(a, b, callback) { return (null, modAresponse); } function modaBStub(a, b, callback) { […]

如何从grunt执行节点模块的茉莉花testing

我想在Grunt构build中为node.js模块运行一些Jasmine 2.xtesting。 我的设置看起来像这样: SRC / foo.js exports.bar = 23; 投机/ foo.spec.js var foo = require("../src/foo.js"); define("foo", function() { it("exports bar as 23", function() { expect(foo.bar).toBe(23); }); }); 随着grunt-contrib-jasmine节点模块系统不可用,我得到 >> ReferenceError: Can't find variable: require at >> spec/foo.spec.js:1 有grunt-jasmine-node ,但是依赖于没有维护的jasmine-node ,包括Jasmine 1.3.1,所以这不是一个选项。 Jasmine通过在spec目录中包含一个jasmine.json文件jasmine.json 支持node.js ,我可以用jasmine cli运行testing。 有没有干净的方式来运行从咕噜同样的testing呢?

茉莉花testing用例不从mongo保存返回

我使用https://github.com/mhevery/jasmine-node来testing我的nodejs服务器路由。 我的mongoose模型有一个工作前置function如下 userSchema.pre('save', function(next) { var user = this; if (!user.isModified('password')) return next(); bcrypt.genSalt(10, function(err, salt) { if (err) return next(err); logger.info('Hashing password!!!'); bcrypt.hash(user.password, salt, null, function(err, hash) { if (err) return next(err); user.password = hash; next(); }); }); }); 现在我需要在jasmine中编写一个testing用例,创build一个userSchema对象并将其保存到mongodb中,以便在testing用例中进一步使用它。 var User = require("../../../../models/User"); it("{postLogin – invalid}", function(done) { var user = new User({email: […]

在jasmine规范中使用module.exports

我想在testing的js中使用module.exports,并使用require()将其包含到指定脚本中。 cat.js – 文件与我想导出的对象 var cat = { name: "filemon", meow: function () { return "miau"; }, walk: function () { return "siup siup siup"; } } module.exports = cat catTest.js – 猫的规范 var cat = require('../app/cat') describe("Cat test", function () { it("cat should meow with miau", function () { expect(cat.meow()).toBe("miau") }) }) 当我使用jasmine CLI(用npm下载)运行testing时,testing通过: […]

茉莉间谍document.execCommand不被调用

我写这样的testing describe('execCommand', function () { it('should call document.execCommand', function () { spyOn(document, 'execCommand').and.callThrough(); expect(document.execCommand).toHaveBeenCalledWith('foreColor', false, 'red'); document.execCommand('foreColor', false, 'red'); }); }); 但它失败Expected spy execCommand to have been called with [ 'foreColor', false, 'red' ] but it was never called. 我不知道为什么 请帮忙。 注意:我使用grunt-contrib-jasmine 0.9.2来运行它

Zombie.js和写入窗口的脚本

我在Zombie.js遇到一些麻烦,并且正在评估将东西写入windowvariables的脚本。 这里是一个例子来展示我的意思: 假设我有一个脚本foo.js ,它执行以下操作: window.foo = 'foo'; 然后我使用zombie.js访问下面的html页面(其中包括foo.js ): HTML <!DOCTYPE html> <html> <head> <title>zombiejs test </title> <script type="text/javascript" src="foo.js"></script> </head> <body> <script type="text/javascript"> console.log(window.foo); </script> </body> </html> 我假设在执行foo.js之后, window.foovariables可以用于页面的其余部分,但是看起来并不如此: Browser.visit('http://localhost:8087/test.html') 给我undefined 。 这有什么特别的原因,或者我在这里做错了什么? Zombie.js是否将脚本评估到与运行页面不同的上下文中?

使用jasmine和grunt对多个版本的jquery进行testing

我已经写了一个jQuery插件的茉莉花testing,我想自动testing我声称支持的每个版本的jQuery。 我已经设置了使用grunt-jasmine-runner运行单个版本的jquery的testing,但是我怎样才能多次运行jasmine任务,每个版本的jquery一次呢? 也可以用qunit吗?

SpecReporter不是茉莉花上的构造函数错误

我尝试使用node.js在茉莉花上configuration简单的项目。 我有以下文件: /*global jasmine */ var SpecReporter = require('jasmine-spec-reporter'); exports.config = { allScriptsTimeout: 11000, specs: [ '**/*.testdev.ts' ], capabilities: { 'browserName': 'chrome' }, directConnect: true, baseUrl: 'foo', framework: 'jasmine', jasmineNodeOpts: { showColors: true, defaultTimeoutInterval: 60000, print: function() {} }, useAllAngular2AppRoots: true, beforeLaunch: function() { require('ts-node').register({ project: 'e2e' }); }, onPrepare: function() { jasmine.getEnv().addReporter(new SpecReporter()); } […]

如何为MVC控制器函数(sails.js)编写简单的茉莉花testing

我想做一个TDD。 但是,我将为我的sails.js项目编写我的控制器函数的testing /*——————— :: Gamble -> controller ———————*/ var GambleController = { index: function(req, res) { res.send('Hello World!'); } }; module.exports = GambleController; 但是,我怎样才能写一个testing来testing输出Hello世界的索引函数呢? 任何人都可以举个例子吗? 谢谢

npm安装jasmine-jquery失败

运行npm install jasmine-jquery给出下面看到的错误输出。 我正在运行Windows 7.任何想法? npm install jasmine-jquery npm http GET https://registry.npmjs.org/jasmine-jquery npm http 304 https://registry.npmjs.org/jasmine-jquery npm http GET https://registry.npmjs.org/jsdom npm http 304 https://registry.npmjs.org/jsdom npm http GET https://registry.npmjs.org/request npm http GET https://registry.npmjs.org/cssom npm http GET https://registry.npmjs.org/contextify npm http GET https://registry.npmjs.org/htmlparser npm http 304 https://registry.npmjs.org/cssom npm http 304 https://registry.npmjs.org/htmlparser npm http 304 https://registry.npmjs.org/request npm http 304 […]