Tag: jasmine

testing需要nodejs中的茉莉花模块

我可以加载需要在节点模块来testing茉莉花。 她的我的规格亚军 var coffee, isVerbose, jasmine, key, showColors, sys, i, len, jasmine = require('jasmine-node'), fs = require("fs"), sys = require('sys'); for (i = 0, len = jasmine.length; i < len; i++) { key = jasmine[i]; global[key] = jasmine[key]; } isVerbose = true; showColors = true; coffee = true; process.argv.forEach(function(arg) { switch (arg) { case '–color': […]

FuncUnit无法使用PhantomJS运行testing

我一直在尝试创build一系列functionunit testing,使用PhantomJS作为浏览器在Node.js Web服务器上运行,在另一个站点上testingfunction。 过去,我已经使用FuncUnit成功地从目标站点本身运行functiontesting,但为了testing规模,我创build了一个Node项目来执行此操作,在Heroku实例上运行。 我用Bower安装了JQuery,Jasmine(我正在使用的testing运行器)和FuncUnit。 我已经被告知,FuncUnit不支持最新版本的Jasmine,所以它在版本1.3.1 – 所有其他软件包在他们的最新版本。 Phantom已经安装了NPM,并打开了以下页面: <html> <head> <title>Functional Testing</title> <script type="text/javascript" src="bower_components/jquery/dist/jquery.js"></script> <script type="text/javascript" src="bower_components/syn/dist/syn.js"></script> <script type="text/javascript" src="bower_components/jasmine-core/lib/jasmine-core/jasmine.js"></script> <script type="text/javascript" src="bower_components/jasmine-core/lib/jasmine-core/jasmine-html.js"></script> <script type="text/javascript" src="bower_components/jasmine-core/lib/jasmine-core/json2.js"></script> <script type="text/javascript" src="bower_components/funcunit/dist/funcunit.js"></script> <script type="text/javascript" src="testSpec.js"></script> <script type="text/javascript"> // Standard Jasmine 1.3 boot script from examples </script> </head> <body> </body> </html> 一旦testing运行开始,我几乎立即遇到错误。 下面的部分似乎会导致崩溃,虽然我很难找出哪一行正如堆栈跟踪已certificate难以导航。 F.attach(jasmine); F.speed = 100; […]

如何使用请求js和jasminetesting一个使用file upload的nodejs POST Web服务?

我使用nodeJS(express)创build了一个带有JSON文件的web服务,读取它并将其内容作为文档存储在mongodb中。 POST路线工作正常。 代码看起来像这样 var multipart = require('connect-multiparty'); var fs = require('fs'); router.post('/', multipartMiddleware, function(req, res) { fs.readFile(req.files.swagger.path, 'utf8', function(err, data) { req.body.swagger = JSON.parse(data); . . }); }); 基本上,它从req.files的JSON文件中req.files并放入req.body对象中。 我需要在Jasmine spec文件上做同样的事情。 我能够使用POSTman物理testingWeb服务,但是我需要使用茉莉花来通过spec文件进行testing。 现在,我想检查一下,Web服务是否会抛出200 OK状态,但是会抛出500 到目前为止,我的jasmine-nodetesting套件看起来像这样 describe("POST /", function() { it("returns status code 200", function(done) { var req = request.post(base_url, function(error, response, body) { expect(response.statusCode).toBe(200); }); […]

为gulp-jasmine设置模块path

我试图unit testing一些Javascript代码与茉莉花使用pegparsing器。 pegparsing器是在构build时build立的。 不幸的是,我还没有发现如何告诉茉莉花dynamic构build的parsing器。 到目前为止,我得到了: gulp.task('parser', () => { return gulp.src("src/parser.peg") .pipe(peg()) .pipe(gulp.dest(".obj")) }); gulp.task('test', ["parser"], () => { return gulp.src(["tests/**/*.js", "src/**/*.js", ".obj/parser.js"]) .pipe(jasmine()) }); 现在,在testing运行的时候,parsing器被正确地构build并放入.obj ; 但它不在模块path上,所以testing加载了真实的代码,真正的代码尝试import parser from "parser" ,并且testing失败。 我可以改变真正的代码来导入../obj/parser而不是parser ,但是这当然会在生产中失败。 我需要以某种方式告诉茉莉花在.objfind模块。 怎么样?

JavaScript – 使用JasminetestingNodeJS readline.createInterface的实现

我在NodeJS中构build了一个命令行应用程序,我想用Jasmine彻底地testing它。 我已经实现了一个promptUser()方法,它使用Node的readline.createInterface方法提出一个问题,并将回应传递给一个callback。 我想testing一下,给定一个' q '的用户响应,我的模块的quit()函数被调用。 不过我正在努力testing这个。 我真的不想直接testingreadline方法,因为我没有写代码,但我推断,如果我可以在process.stdout.write上创build一个监听器,那么当enter command:打印到屏幕上,我可以用process.stdin.write("q\n")回应并触发if / else逻辑。 我简化了代码,但是应该解释我正在做的事情: 模块源代码: var Cli = function() { var rl = require('readline'); var self = this; Cli.prototype.promptUser = function() { var inputHandler = rl.createInterface(process.stdin, process.stdout); inputHandler.question('enter command: ', function(answer) { if (answer === 'q') { self.quit(); }; }); }; Cli.prototype.quit = function() { // doSomething }; […]

Supertest期望不正确地声明状态码

我有一个像这样的testing: it('should fail to get deleted customer', function(done) { request(app) .get('/customers/'+newCustomerId) .set('Authorization', 'Bearer ' + token) .set('Accept', 'application/json') .expect('Content-Type', /json/) .expect(404, done) }); 我已经阅读了这里的文档: https://github.com/visionmedia/supertest 它说: 注意如何直接传递给任何.expect()调用 不工作的代码行是.expect(404, done)如果我改变这个.expect(200, done)那么testing不会失败。 但是,如果我添加这样的结尾: it('should fail to get deleted customer', function(done) { request(app) .get('/customers/'+newCustomerId) .set('Authorization', 'Bearer ' + token) .set('Accept', 'application/json') .expect('Content-Type', /json/) .expect(200) .end(function(err, res) { if […]

如何在浏览器中运行茉莉花节点testing(例如使用testem)?

如何在浏览器中使用testem( https://github.com/testem/testem )运行jasmine-node( https://github.com/mhevery/jasmine-node )testing? 他们都在nodeJS上运行,但我不知道如何将它们结合起来。 我想知道是否有任何我可以使用的库,或者是否有人成功定制了两个库来在浏览器中loggingtesting输出。

如何与jasmine-node一起使用jsdom.jQueryify?

用jasmine的jQueryifyfunction可以使用jasmine-node吗? 我想要做的就是使用NodeJS来testing一些依赖于DOM存在的JavaScript。 这是我尝试的一个减less的情况。 当我运行这个脚本时,jasmine-node识别这个规范,但是不运行expect() : var fs = require('fs'), jsdom = require('jsdom'), window = jsdom.createWindow(), jasmine = require('jasmine-node') describe("jQueryify", function() { it('should run the test!', function () { jsdom.jQueryify(window, function (window, jquery) { expect(1).toEqual(1) }) }) }) 或者,是否有不同的/更好的方式来testingNodeJS中的假设类似浏览器的环境?

未能在茉莉花节点中显示的testing

我有一个Web服务的基本testing: var request = require('http'), url = 'http://localhost:1337/'; describe('webservice', function() { it('should respond to /ping', function(done) { request.get(url + 'ping', function(res) { expect(res.statusCode).toBe(200); res.on('data', function(body) { var json = JSON.parse(body); expect(json.message).toBe("Hi, I'm alive"); expect(json.date).toBeDefined(); done(); }); }); }); }); 这似乎工作正常: $ jasmine-node –verbose tests/ping/ webservice should respond to /ping Finished in 0.032 seconds 1 test, […]

用jasmine监听asynchronous函数

我正在使用茉莉花节点来testing我的服务器。 我想伪造/绕过我的用户类中的一些validation相关的代码。 所以我会设置一个这样的间谍 – var user = { email: 'email@email.com', password: 'password' } spyOn(User, 'validateFields').andReturn(user); 但是validateFields函数是asynchronous的… User.prototype.validateFields = function(user, callback) { // validate the user fields callback(err, validatedUser); } 所以我实际上会需要这样的一个callback而不是回报 – var user = { email: 'email@email.com', password: 'password' } spyOn(User, 'validateFields').andCallback(null, user); 茉莉花是可以做到的吗?