Tag: 摩卡

摩卡testing永远运行

大家好,感谢您的关注。 我正在尝试使用摩卡和超级terminal来运行testing,即使这些testing工作正常,testing也会一直运行。 为了避免这种情况,我在after()方法中添加了一个“process.exit(0)”,所以它可以正确的构build,但是这对于“隔离”看起来确实是错误的(除此之外,它看起来很糟糕:-)) 我的package.json: { "name": "application-name", "version": "0.0.1", "private": true, "scripts": { "start": "nodejs ./bin/www", "test": "mocha" }, "dependencies": { "body-parser": "~1.0.0", "cookie-parser": "~1.0.1", "debug": "~0.7.4", "ejs": "~0.8.5", "express": "~4.0.0", "is-my-json-valid": "^2.16.1", "knex": "^0.13.0", "morgan": "~1.0.0", "mysql": "^2.14.1", "static-favicon": "~1.0.0" }, "devDependencies": { "mocha": "^4.0.0", "supertest": "^3.0.0", "chai": "^4.1.2", "util": "^0.10.3" } } 我的testing: […]

primefaces+摩卡在窗户=派生摩卡ENOENT

我的目标是通过安装在Windows上的Atom运行摩卡unit testing,同时我的src代码也驻留在这里。 这应该独立于我的meteor应用程序运行在不同的(Linux)机器上。 基本上我的设置是这样的: 我有我的回购和源代码: c:\Users\Me\repos\meteor 我的testing是在里面: c:\Users\Me\repos\meteor\tests 我有节点: c:\Program Files\nodejs 安装了"npm i -g mocha –save-dev" 而我尝试使用这个包https://github.com/Tabcorp/atom-mocha-test-runner,但我可以切换到另一个包,如果有必要。 我到目前为止所尝试的是: 我编辑了我的primefaces摩卡testing运行器的设置: Mocha command: C:\Program Files\nodejs\node_modules\mocha\.bin\mocha Mocha command: C:\Program Files\nodejs\npm mocha 但每次我尝试通过下拉菜单运行我的testing(运行摩卡testing),我得到这个错误: Mocha Test Results: Node binary: C:\Program Files\nodejs\node.exe Root folder: C:\Source\Repos Mocha command: undefined Path to mocha: mocha Debug-Mode: false Test file: tests\unit\first.js Selected test: should return […]

摩卡testing表示启动

如果缺less参数(例如数据库URI),我的快速服务器会抛出一个错误。 我想在摩卡testing它实际上抛出了错误,但我不知道如何让摩卡这样做。 if(!parameters.db) { throw new Error('Please provide a db URI'); } 我有一个像这样的testing设置: it('Throws Error when no db URI provided in production mode', function () { expect(require('../server')).to.throw(); done(); }); 当我的快速应用程序抛出错误,错误被扔进控制台和testing失败(实际上,它不会结束)。 我遇到的另一个问题是,如果环境处于生产模式,Express仅检查参数。 我试图在testing套件中设置stream程环境到生产环境,但是当我运行它时, NODE_ENV仍然被设置为“testing”。 before(function() { env = process.env; // This doesn't really set the environment when I run the tests. process.env.NODE_ENV = 'production'; });

使用typecrit / mocha进行unit testing时找不到模块

对于Typescript,我是一个相当新的东西,并试图在本教程之后设置一个项目: http ://mherman.org/blog/2016/11/05/developing-a-restful-api-with-node-and-typescript/ 我正在创build一个名为helloworld.test.ts的文件,并运行npm test来查看api的基本路线是否正常工作。 但是,当我运行npmtesting命令(哪些做: mocha –reporter spec –compilers ts:ts-node/register 'test/**/*.test.ts' )我得到以下错误: /home/louis/Bureau/my-simple-project/node_modules/ts-node/src/index.ts:312 throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset)) ^ TSError: ⨯ Unable to compile TypeScript Cannot find type definition file for 'body-parser'. (2688) Cannot find type definition file for 'chai'. (2688) Cannot find type definition file for 'chai-http'. (2688) Cannot find type definition […]

Observable的简单testing结果与柴和摩卡nodejs

我正在开发一个应用程序使用Nodejs,RxJS和Typescript。 该应用程序有一个返回一个string的Observable的函数 myObsFunction() : Observable<string> { … do stuff } 我想能够做一个简单的testing来检查,当我订阅这个函数,我得到预期的string。 我使用柴和摩卡 ,所以我写下面的testing用例 import { expect } from 'chai'; import 'mocha'; import {myObsFunction} from './my-source-file'; describe('myObsFunction function', () => { it('check myObsFunction', () => { const expectedString = 'abc'; let receivedString: string; myObsFunction().subscribe( data => receivedString = data, error => console.error(error), () => expect(receivedString).to.equal(expectedString) ) […]

unit testingNodeJS Promise里面的一个函数

我试图unit testing一个函数,调用承诺… 使用摩卡,Sinon。 我有这样的function块: myfile.js: let OuterDependecy = require('mydep'); function TestFunction(callback) { OuterDependency.PromiseFunction().then(response => { //some logic here }).catch(err => {callback(err)}); 在我的testing里面,我使用了一些代用品来嘲弄外在的东西 testfile.js let proxyquire = require('proxyquire'); let OuterDepStub = {}; let testingFunc = proxyquire('myfile.js', {'mydep': OuterDepStub}); 然后在我的testing块内 let stubCallback = function() { console.log('Stub dubadub dub'); //note…i can use sinon.spy here instead }; beforeEach(()=>{ OuterDependency.PromiseFunction […]

模拟外部依赖

//user.js couchdb = require('couchdb'); exports.create = function(req, res){ user = req.body if( validate(user) ) { couchdb('db').insert(user); //redirect } else { //render new again with the user }; }; 我想testing上面的函数是否创build了一个用户。 //user_spec.js describe('User create', function(){ beforeEach( function(){ //call create with valid user }); it('should create a user', function(){ //test database for user assert( fakeDatabase.users.length, 1) }); }) […]

当在节点下运行基于摩卡咖啡脚本的testing时,意外的' – >'

我正尝试在Windows下的节点上运行摩卡。 我也决定为什么不扔一些CoffeeScript的乐趣。 describe 'Array', -> describe '#indexOf()', -> it 'should return -1 when not present' -> [1,2,3].indexOf(4).should.equal -1 问题是我遇到了一个错误: C:\Users\ShaneC\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\coffee-script.js:51 throw err; ^ Error: In C:\projects\BowlingKata\test\test.coffee, Parse error on line 3: Unexpected '->' at Object.parseError (C:\Users\ShaneC\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\parser.js:477:11) at Object.parse (C:\Users\ShaneC\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\parser.js:554:22) at C:\Users\ShaneC\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\coffee-script.js:43:20 at Object..coffee (C:\Users\ShaneC\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\coffee-script.js:19:17) at Module.load (module.js:353:31) 这是我的mocha.opts文件: –reporter spec –ui bdd -r should –compilers […]

在Windows上使用主pipe重新运行摩卡

我正尝试使用主pipe重新运行摩卡testing。 我努力了: supervisor node_modules\.bin\mocha 它进入循环与错误: basedir=`dirname "$0"` build议?

摩卡testing,之前(每个)不运行?

我试图testing我的mongoose模型,如: Todo =需要“../../../app/todos/Todo” describe "Todo", -> describe "Basic CRUD", -> before: (done) -> console.log "In b4" Todo.remove {}, (err) -> console.log "removed" done err it "can be added to database", (done) -> todo = new Todo title: "New todo" todo.save (err) -> if !err Todo.find { title: "New todo" }, (err, docs) -> docs.length.should.equal 1 […]