Tag: unit testing

sinon存根不能在nodejstesting中工作

我正在编写Invoicer模块的testing。 我的testing有两个问题。 第一个是邮件仍然被发送,尽pipe已经emailjs模块(第一次testing),第二个问题是我的第二次testing超时后2secs。 我不明白为什么? 有谁能帮我解决这个问题吗? Invoicer 'use strict'; var fs = require('fs'); var _ = require('underscore'); var request = require("request"); var email = require("emailjs"); exports.Invoicer = function (url, context) { // set-up our transporter object with credentials var transporter = email.server.connect({ user: 'Pinoquio', password: 'sdlfkjlj', host: "pinoquio@gmail.com", port: 444, tls: true }); // read html […]

节点unit testing – TypeError:无法读取未定义的属性“顺序”

我收到以下错误, Error: BLANKET-Error parsing instrumented code: TypeError: Cannot read property 'order' of undefined我的testing代码Error: BLANKET-Error parsing instrumented code: TypeError: Cannot read property 'order' of undefined指示其中testedModule = proxyquire('../index', { 任何人都可以看到为什么我得到这个错误? 我的testing文件: pattern: function (filename) { return !/node_modules/.test(filename); } }); // in terminal, type the following command to get code coverage: mocha -R html-cov > coverage.html var chai […]

Babel不与Mocha一起工作并启动Node服务器

我正在帆和摩卡上运行sailsjs,mocha和babel。 当我运行之前,我的前function启动帆应用程序运行testing之前,我得到这个: > PORT=9999 NODE_ENV=test mocha –recursive –compilers js:babel/register lifting sails 1) "before all" hook 0 passing (757ms) 1 failing 1) "before all" hook: Uncaught Error: only one instance of babel/polyfill is allowed 对于我的生活,我无法弄清楚如何让摩卡运行巴贝尔同时运行巴贝尔的工作。 我的before()代码如下所示: import Sails from 'sails' // Global before hook before(function (done) { console.log('lifting sails') // Lift Sails with test database Sails.lift({ […]

用Sinon嘲笑require()函数

我试图在使用Sinon的testing中嘲讽request-promise 。 据我所知,Sinon嘲笑对象的方法,但request-promise只是返回一个函数。 有没有什么办法来模拟一个必需的function? var rp = require('request-promise'); var User = require('../../models/user'); // this works sinon.stub(User, 'message', function() {}); // This is what I'd like to do to request-promise sinon.stub(rp, function() {}); 我也研究过mockrequire和proxyquire,但我认为他们都遇到类似的问题。

使用NodeJS使用OAuthunit testingMobileFirst Platform Java适配器

我正在编写一个NodeJS应用程序来testing我写的IBM MobileFirst Platform适配器。 我想遵循的方法做到这一点,如下所示: 从http:// localhost:10080 / AppName / authorization / v1 / testtoken获取testing令牌 使用此不记名令牌对我受保护的适配器进行authentication请求。 方法的问题是,当我尝试向testtoken端点发出请求时,出现HTTP 405状态错误。 但是,PostMan也一样。 有没有办法使这个工作在NodeJS应用程序? 我正在使用请求发送请求到MobileFirst服务器。 我正在使用SailsJs编写我的NodeJS应用程序。

Node JS Jasmine用jasmine.any()testing多个types

我正在使用茉莉花( v2.2.0 )进行testing,我试图窥探一个方法,预计将调用第一个参数的具体数据,第二个未知types。 我熟悉间谍和间谍 .toHaveBeenCalledWith()语法,并joinjasmine.any()它可能看起来像这样: expect(my.spy).toHaveBeenCalledWith('startMenu', jasmine.any(String)); 但我无法find一种方法来处理几种types。 我正在寻找的是一种方法来执行相同的行动,其中第二个参数是任何types,以及当第二个参数是某些types之一,如: // Any type is okay: expect(my.spy).toHaveBeenCalledWith('startMenu', jasmine.any()); // String or number only: expect(my.spy).toHaveBeenCalledWith('startMenu', jasmine.any(String OR Number)); 不用说,前面的例子不是工作代码,他们正是我正在寻找正确的语法。 另一个说明,我发现jasmine.anything() 几乎可以处理任何事情,但未能undefined 。 任何forms的帮助,非常感谢。

TDD只适用于模型或其他地方

我已经从Kent Beck那里买了“TDD的例子”,我已经读了关于Money谈话和计算的第一部分。 在进一步阅读之前,我有一些问题。 TDD是否仅与域特定部分相关? 我的情况如下 我是nodejs开发人员,我在REST API上工作。 在nodejs中,我们使用路由callback(就像控制器),我想知道在处理TDD时是否需要进行一些集成testing? 或者我应该只将它应用到我的服务/存储库/实体? (我知道我必须进行集成testing,但是我想知道如何将它应用于TDD原则,我发现它确实是以域为导向的) 当处理移动开发(在我的情况下是Android本地),活动(像控制器一样)不关心TDD的工作方式吗? 因为它也意味着集成testing,我觉得呢?

如何使用debugging器运行javascripttesting; 声明?

似乎没有一个普遍的答案,也没有要求堆栈溢出。 我来自Python的背景,我可以使用import pdb; pdb.set_trace() import pdb; pdb.set_trace()在我的代码中,并立即通过代码使用debugging器。 我如何在NodeJS中做到这一点? 例如,我试图在Browserify Shim中运行和debuggingtesting。 这使用npm的taptesting框架 。 要运行testing,我需要从Browserify-shim的根目录运行npm run test-main 。 如果我添加一个debugger; 代码或testing中的语句,什么都不会发生。 我试过运行npm run test-main –debug以及npm run test-main –debug-brk无济于事。 在NodeJS中有效地遍历代码的正确方法是什么?

testing同一个函数的并发调用

我有一个function: var inRendering = false; function render() { if (inRendering) { requestAnimationFrame(render); } else { inRendering = true; requestAnimationFrame(function () { longAction(); inRendering = false; }); } } 我必须进行unit testing。 testing并发调用render 。 请帮帮我? 这样的并发呼叫在JavaScript中可能吗? 谢谢。 PS我写了一个testing,显然不工作(见评论): https : //gist.github.com/kuraga/b0aa3d66fc0620f03b11

如何在调用时从spy.on(obj,'funcName')返回假数据?

我不知道有没有function! 请让我知道这有可能吗? 类似的东西: spy(obj, 'funcName').and.returnValue(5); // spy will return a fake data when 'funcName'called. 那么我正在使用mocha , chai-spies