我有一个要测试的简单javascript包。我想检查是否抛出了错误,但是当我的测试运行并抛出错误时,测试被标记为失败。代码如下:varshould=require('chai').should(),expect=require('chai').expect();describe('#myTestSuite',function(){it('shouldcheckforTypeErrors',function(){//Pulledstraightfromthe'throw'sectionof//http://chaijs.com/api/bdd/varerr=newReferenceErr
所以我有这段代码:describe('maindescribe',function(){afterEach(function(){//this.prop===undefined});describe('sub',function(){it('shoulddosomething',function(){this.prop='test';});});});我不知道为什么mainafterEach中的this.prop是undefined因为下面的代码按预期工作:describe('maindescribe',function(){afterEach(function(){//this.pr
ES6、Windows10x64、Node.js8.6.0、Mocha3.5.3是否可以在Mocha测试中使用ES6模块?我遇到了export和import关键字的问题。/*eventEmitter.js*//*Eventemitter.*/exportdefaultclassEventEmitter{constructor(){constsubscriptions=newMap();Object.defineProperty(this,'subscriptions',{enumerable:false,configurable:false,get:function(){returns
我是node.js和用于单元测试的框架Mocha的新手,但我在cloud9IDE中创建了几个测试只是为了看看它是如何工作的。代码如下所示:varassert=require("assert");require("should");describe('Array',function(){describe('#indexOf()',function(){it('shouldreturn-1whenthevalueisnotpresent',function(){assert.equal(-1,[1,2,3].indexOf(5));assert.equal(-1,[1,2,3].index
是否可以在浏览器版本的Mocha中使用多个记者?我正在创建一个将测试结果发送到我的服务器的记者,但我仍然想使用Mocha默认的默认HTML记者。现在我正在修改源代码以使其正常工作。我知道Mocha也为其记者使用commonJS。 最佳答案 mocha.run返回一个运行器对象,它发出有用的事件,例如'testend'和'suiteend'。因此,我们可以这样做:mocha.run().on('testend',function(test){if('passed'===test.state){console.log('passed!'
我正在使用gruntjs和grunt-simple-mocha运行mocha测试:https://github.com/yaymukund/grunt-simple-mocha如何在每个mocha测试中访问grunt.js文件中定义的选项?我想要完成的是在我的gruntfile中有一些通用配置,并在我的测试中使用它。 最佳答案 我已经找到的一种方法是使用全局值,这不是很好,但是有效在grunt.js配置中global.hell='heyyou';内部测试console.log(global.hell);现在多检查一种方式,也许会更好
我正在尝试在beforeHook中获取当前的describe名称,如下所示:describe('increasing3times',function(){before(function(){console.log('testname');});...});我基本上想在before钩子(Hook)中检索'increasing3times'字符串。如何实现?谢谢! 最佳答案 下面是说明如何执行此操作的代码:describe("top",function(){before(function(){console.log("fulltitle
您好,作为问题的标题,我想知道如何在启动测试之前检查环回引导脚本是否已完成。在示例项目中:https://github.com/strongloop/loopback-example-relations有一个file在似乎可以完成工作的测试文件夹中,但不幸的是它没有解决它。start-server.js:varapp=require('../server/server');module.exports=function(done){if(app.loaded){app.once('started',done);app.start();}else{app.once('loaded',fu
我知道before、beforeEach、after和afterEach但我如何在ALL之前运行一些代码测试。换句话说,我是这样归档的testtest1.jstest2.jstest3.js我用运行测试mocha--recursive我不想在每个测试文件中都添加一个before。我需要一个beforeAllTests或一个--init=setup.js或我可以在执行任何测试之前执行一些JavaScript的东西。在这种特殊情况下,我必须在测试运行之前配置系统的日志记录模块有没有办法调用一些在所有测试之前执行的初始化函数? 最佳答案
我正在使用Protractor(0.22.0)来测试我的应用。这可能有一个Mocha式记者而不是基本的Jasmine式记者吗?目前看起来像这样:(....F...)我看起来更像:mysetoftests1mytest1-1mytest1-2mysetoftests2mytest2-1mytest2-2 最佳答案 请在此处查看回复:CustomJasminereporterinProtractortests我正在使用这个模块,它工作得很好:https://www.npmjs.com/package/jasmine-spec-repor