Tag: 摩卡

Babel不会忽略我的模块的正则expression式

我正在使用Mocha在我的React组件上运行testing,因此我需要在我的Mocha引导程序中使用Babel来传输jsx需求。 在我的bootstrap.js我开始 global.babel = require("babel/register")({ ignore: [/node_modules/, '**/scss*', /sinon/, /foo/] }); 根据文档 ,忽略接受“一个glob,正则expression式,或混合数组”,但它的奇怪,因为/node_modules/, /sinon/ regexes工作,但**/scss*和/foo/不。 例如,以下是不符合要求的组件的顶部: var React = require('react'); var Router = require('react-router'); var Link = Router.Link; var foo = require('foo'); var StyleSheet = require('../../scss/core/Linker'); 失败: 1) app/core/Linker.jsx "before each" hook: Error: Cannot find module 'foo' at Object.<anonymous> (app/core/Linker.jsx:4:11) at Context.<anonymous> (test/app/helpers/linker-test.js:10:23) 我开始这样的testing: mocha […]

摩卡istanbul不包括一个文件

我正在使用grunt mocha istanbul来运行我的testing用例并检查代码覆盖率。 当我运行命令npm test时,每个文件中的所有testing用例都被执行。 但是,当涉及到代码覆盖率时,其中一个文件没有被检查。 有趣的是,该文件夹中的所有文件都已经过代码覆盖testing。 我无法find任何指出问题出在哪里的错误日志。 有人可以指导我吗?

无效的属性发送到Passport错误桶风帆

我正在申请帆。 我正在使用桶将数据填充到我的模型中。 填充用户后填充护照时出现以下错误。 以下是我的user.json和passport.json [ { "communityID": 1, "email": "testuser@getintuch.com", "ownershipGroups": [1], "membershipGroups": [1] } ] [ { "protocol": "local", "password": "random", "accessToken": "random", "user": 1 } ] barrels.populate(['user'], function (err) { if (err) return done(err); barrels.populate(['passport'], function (err) { if (err) return done(err); done(err, sails); }); }); 以下是我得到的错误 Error (E_VALIDATION) :: 1 attribute is […]

mongoose模式unit testing失败与前保存挂钩

使用“预保存”mongoose钩似乎会导致我的unit testing超时(超过2000毫秒的错误)。 当我注释掉预保存钩子时,unit testing工作正常……但是当包含pre-save-hook时,testing超时并且不返回任何特定的错误消息。 任何想法可能是错的? 模型(User.js) var mongoose = require('mongoose'); var bcrypt = require('bcrypt'); var Schema = mongoose.Schema; var userSchema = new Schema({ "auth": { "local": { "email": String, "password": String, } }, "userProfile" : { "firstname" : {"_default": String}, "lastname" : {"_default": String}, "username": String, "email" : String, } }); userSchema.method('genHash',function(password){ return bcrypt.hashSync(password, bcrypt.genSaltSync(9)); […]

用摩卡回收的sails.js

我有某些摩卡testing需要重新提升使用moduleLoaderOverride模拟某些策略的不同configuration的sails。 一般来说,这是工作,但似乎帆不降低和重新正确提升。 为testing执行sails实例所有pipe理的实用程序文件: // util var Sails = require('sails/lib/app'), sails; module.exports = { sailsInstance: undefined, testConfigs: {}, start: function(callback) { this.sailsInstance = new Sails(); /* This config will NOT be enforced for the remaining tests, it is just a quick lift so our code can use sails config parser and extract the other configs easily. […]

Sails.js和Mocha:使用supertest:path问题,当控制器在像api \ controllers这样的coustom文件夹被移动到api \ controllers \ admin

而我正在做testing代码,如果我把控制器在默认位置“API \控制器\”。 它运行完美没有错误,但是当我将其更改为'api \ controllers \ admin \'。 它给错误。 ==>当控制器在默认位置“API \控制器\” 我的代码是在config / routes.js 'post /state/create': 'StateController.create', 和testing代码是 var request = require('supertest'); describe('StateController', function() { describe('#create()', function() { it('State already in table /create', function (done) { request(sails.hooks.http.app) .post('/state/create/') //Path and method .send({ name: 'gujarat', country_id: '55d452f20424cda40df0f3de' }) .set('Accept', 'application/json') .expect('Content-Type', /json/) .expect(800) .end(function(err, res){ if […]

在Node not io.js的Mochatesting中使用jQuery

我正在运行使用jQuery(对于Ajax调用)的模块的摩卡/柴unit testing,当然,jQuery抱怨丢失的文档,因为我运行没有浏览器的testing。 我发现创build虚拟dom的jsdom模块可以欺骗jquery,但是项目已经抛弃了node.js而转向了io.js,并且不能和node一起使用。 我不认为我想在项目中间切换到io.js,所以我的问题是: 目前在命令行的摩卡testing中使用jQuery的方法是否存在?

无法使用摩卡开始testing

以下是我运行摩卡testing时遇到的错误… upquire@0.0.0 test D:\tecsol\mtv mocha test/bootstrap.test.js test/unit/**/*.test.js 1) "before all" hook 0 passing (3m) 1 failing 1) "before all" hook: Error: timeout of 50000ms exceeded. Ensure the done() callback is being called in this test. at null.<anonymous> (D:\tecsol\mtv\node_modules\mocha\lib\runnable.js:189:19) 以下是我的bootstrap.test.js文件: var Sails = require('sails'); var sails; before(function(done) { this.timeout(5000); Sails.lift({ // configuration for testing purposes }, […]

如何让Sinon的fakeServer在Mocha和Node中响应jQuery.ajax调用?

我在这里看了很多答案,那里有博客文章,在Sinon自己的问题跟踪器中发布的问题,还没有发现任何明确的。 我到目前为止大概是: import XMLHttpRequest from "xhr2"; … beforeEach((done) => { jsdom.env("<!doctype html><html><body><div></div></body></html>", (error, window) => { for (var i in require.cache) {delete require.cache[i];} Object.assign(global, _.pick(window, "document", "navigator")); global.window = window; window.console = global.console; document.body.dataset = {}; … global.$ = require("jquery"); global.$(() => { global.$.support.cors = true; global.$.ajaxSettings.xhr = () => {return new XMLHttpRequest();}; const fakeServer […]

摩卡返回“callback不是一个函数”asynchronous调用

我正尝试使用nodejs(es6 + babel)和mocha一起。 这是我testing的基类: import cheerio from 'cheerio'; import ResourceRequest from './ResourceRequest'; export default class HtmlValueParser { constructor(url, headers) { this.rr = new ResourceRequest(url, headers); this.body = null; this.$ = null; } getValue(query) { if (!query) { return; } if (this.$ === null){ this.$ = cheerio.load(this.body); return 'toto'; }else { return 'titi'; } } getAValue(query, […]