Tag: mocha

你怎么能正确地要求在mocha.opts模块?

我正在用mocha- mongoose在testing之间自动清除mongo。 在文档中说要在您的spec文件中需要模块或者在您的spec帮助程序中全局使用。 根据规范做它很好,但我想从mocha.opts做到这一点,以保持我的代码干爽。 要求与mocha.opts不起作用。 Mongo在规格之间没有被清除 mocha.opts: –require ./test/common.js –reporter spec –ui bdd –recursive –colors –timeout 60000 –slow 300 common.js: require('mocha-mongoose')('mongodb://your-mongodb-url-here'); 要求在每个spec文件中工作 test.js var should = require('chai').should() , require('mocha-mongoose')('mongodb://your-mongodb-url-here'); describe("Example test", function() { it(' Mongo will be automatically clear all collections',); }); 我怎样才能在mocha.opts中正确地要求mocha-mongoose mongoose,所以我不必在每次testing中重复它呢?

用testing数据库testingStrongloop RESTapi

我正在使用Strongloop开发Web应用程序,该应用程序将在Bluemix(云平台服务)上运行。 我的问题是,当我testing我想testing运行对另一个数据库,而不是内存数据库。 我有两个问题关于如何做到这一点: 是/我该如何configuration一个特定的数据库应该在运行testing时使用? 作为部署的一部分,我希望能够在Bluemix上部署时运行testing。 所以,如果我没有错,这是不够的,如果我可以手动使用一些参数设置什么数据库将运行时,我正在做一个“节点”。 另外在我的server.js我这样做我的数据库同步我的datamodel: var appModels = ['User']; var ds = app.dataSources.eventSeedElephantSQLDb; ds.isActual(appModels, function(err, actual) { if (!actual) { ds.autoupdate(appModels, function(err) { if (err) throw (err); }); } }); 当我正在运行testing,我想运行类似的东西,而是我想迁移。 在testing中,我使用摩卡,柴和柴哈特。

使用摩卡在Sublime上debuggingJavaScript代码

我写了一些testing用例,并用摩卡执行它们。 我使用崇高作为编辑。 当我运行testing用例(使用摩卡)时,我想添加debugging点,并希望看到发生了什么。 如果不是SubLime,有没有办法在浏览器上执行这些testing用例,并在浏览器中添加断点? 如果这种方法是不实际的我有什么其他的select? 谢谢

validation使用Mocha / Chai和asynchronous/等待引发exception

我努力想出一个最好的方法来validation在使用asynchronous/等待的同时在摩卡testing中拒绝承诺。 这是一个should.be.rejectedWith的例子,但我不喜欢should.be.rejectedWith返回一个承诺,需要从testing函数返回,以正确评估。 使用async / await可以删除testing值的这个要求(正如我对下面wins()的结果所做的那样),我觉得在某些时候我很可能会忘记return语句,在这种情况下,testing总是会通过。 // Always succeeds function wins() { return new Promise(function(resolve, reject) { resolve('Winner'); }); } // Always fails with an error function fails() { return new Promise(function(resolve, reject) { reject('Contrived Error'); }); } it('throws an error', async () => { let r = await wins(); r.should.equal('Winner'); return fails().should.be.rejectedWith('Contrived Error'); }); 感觉应该有可能使用async […]

在目录中运行所有'test.html'文件 – mocha-phantomjs

我有一个模块,我使用mocha-phantomjs来testing这个模块。 我创build了package.json文件 { "name" : "demo-test", "scripts": { "test": "npm run test-debug", "test-debug": "mocha-phantomjs ./test/Test1.html" }, "dependencies" : { "mocha" : "1.13.x", "commander" : "1.2.x", "which" : "~1.0.5", "mocha-phantomjs": "3.3.2" }, "devDependencies" : { "chai" : "1.8.x", "coffee-script" : "1.6.x", "requirejs" : "2.1.x", "jquery" : "2.1.0" } } 然后我运行npm install ,然后npm test来运行testing。 它工作正常,并运行test1.html的testing。 现在我想要在testing目录下的所有文件(test1,test2,…)在执行npm test执行。 […]

如何暂停或等待在摩卡testing案例 – setTimeout不工作

我build了一个selenium摩卡testing用例打开谷歌,input一些文本,然后单击search。 这是我的selenium摩卡testing用例代码片段 但是我只需要在inputsearch文本60秒后执行点击search var assert = require('assert'), test = require('selenium-webdriver/testing'), webdriver = require('selenium-webdriver'); var urladd ='http://www.google.com/'; function clickLink(link){ link.click(); return link; } var testSimple=function(searchContent){ var browser = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build(); test.describe('\n\nGoogle Search\n', function() { this.timeout(60000); test.it('Enter element to be searched', function(done) { browser.get(urladd); browser.findElement(webdriver.By.name('q')).sendKeys(searchContent); browser.getTitle().then(function(title) { assert.equal(title,'Google'); }) }); test.it('Click search button', function(done) { setTimeout(function(){ browser.findElement(webdriver.By.name('btnG')).then(clickLink).then(function(){ […]

在debugging摩卡testing时,Visual Studio代码中的断点没有命中

我正在使用Mocha(和Chai)进行NodeJS模块的unit testing,并且希望在Visual Studio代码中进行debugging。 我在test子文件夹中有一些TypeScript文件,并test了一些testing。 VScode在out目录中生成.js和.map文件(通过tsc watch模式任务)。 我的tsconfig.json文件包含这些设置: { "compilerOptions": { "compileOnSave": true, "module": "commonjs", "target": "es6", "outDir": "out", "removeComments": true, "noImplicitAny": true, "sourceMap": true, "inlineSources": true, "isolatedModules": false, "allowSyntheticDefaultImports": true, "experimentalDecorators": true }, "include": [ "src/**/*", "parser/**/*", "test/**/*" ], "exclude": [ "node_modules", ".vscode-test" ] } 外面包含3个包含3个子目录。 迄今为止都很好。 我可以使用这个命令运行我的testing: mocha –compilers ts:ts-node/register,tsx:ts-node/register 在vscode之外。 然后,我用–debug-brk开关运行了这段代码,并将vscode连接到它。 这有效,但没有断点。 launch.json中的configuration是: […]

testingAngularJS express节点的应用程序

我有一个与jasmine-node和mocha (与zombie )testing我的应用程序的问题。 重点是angular不适用于这个testing环境 – 当browser.visit "http://localhost:3000/"它只显示布局,并且不显示任何模板链接 。 我猜javascript不会在浏览器(我的意思是僵尸对象)中运行。 我的testing是否有任何方法使其工作? 或者问题是不同的? 在茉莉花规范,我从另一个项目规范复制发生错误: /home/alder/Node/angular-express-coffee/spec/app_spec.coffee:12 throw error; ^ ReferenceError: angular is not defined at /js/services.js:4:3 at /js/services.js:6:4 in /js/services.js 所以我想JavaScript不起作用。 更新:我添加debugging选项,并在这里显示它: ➜ angular-express-coffee git:(master) ✗ mocha –require should –compilers coffee:coffee-script –colors -R spec –ui bdd Given I am a new user When I visit the home page […]

使用Sinon在javascript中扼杀Redis交互

我在node.js工作。 我的应用程序通过node_redis模块与Redis进行交互。 我正在使用摩卡和sinon来自动testing我的应用程序。 我的应用程序看起来像这样: …snip var redisClient = redis.createClient(redisPort, redisHost); var someValue = redisClient.get("someKey"); return someValue; …. 我想将呼叫存根到redisClient.get()。 要做到这一点,我也需要存根调用redis.createClient() – 我认为…这是我的testing代码: … var redis = require("redis"); var redisClient; … sinon.stub(redisClient, 'get').returns("someValue"); sinon.stub(redis, "createClient").returns(redisClient); … assert.equal(redis_client_underTest.call_to_redis(), "someValue"); … testing失败与AssertionError: false == "someValue" 我如何将redisClient存根,或者甚至可能呢?

摩卡路线testing不是asynchronous执行的

我已经开始与摩卡工作,我有一个特定的testing案例的问题。 这里是代码: var assert = require("chai").assert; var request = require('supertest'); var http = require("http"); var conf = require("../config/config"); var app = require("../app"); var mongoose = require('mongoose'); var User = mongoose.model('User'); describe('User controller', function(){ describe('POST /register', function(){ it('should return false when the parameters are not unique', function (done) { request(app) .post('/user/register') .send({username:"janette_doe", email:"janette_doe@gmail.com", password:"test123"}) .expect('Content-Type',/json/) .expect({success:true, […]