我对单元测试、mocha和should.js非常陌生,我正在尝试为返回promise的异步方法编写测试。这是我的测试代码:varshould=require("should"),tideRetriever=require("../tide-retriever"),moment=require("moment"),timeFormat="YYYY-MM-DD-HH:mm:ss",from=moment("2013-03-06T00:00:00",timeFormat),to=moment("2013-03-12T23:59:00",timeFormat),expectedCount=30
我有两个测试(A,B)的简单示例,其中B取决于正在运行的A。如果我使用的是Mocha,我可以在A中嵌套测试B:describe.only('AB:',function(){describe('A',function(){it('A1',function(){assert.equal(1,2);});describe('B',function(){it('B1',function(){assert.equal(1,1);});});});});但即使A失败,A和B也会运行。这与不使用嵌套有何不同?describe.only('AB:',function(){describe('A&B',
我有以下测试用例:it("shouldpassthetest",asyncfunction(done){awaitasyncFunction();true.should.eq(true);done();});运行它断言:Error:Resolutionmethodisoverspecified.SpecifyacallbackorreturnaPromise;notboth.如果我删除done();语句,它断言:Error:Timeoutof2000msexceeded.Forasynctestsandhooks,ensure"done()"iscalled;ifreturningaP
我确定我在这里遗漏了一些明显的东西!我已经阅读了此处的说明(https://github.com/visionmedia/mocha/wiki/Third-party-reporters),并获取了他们的代码并将其添加为一个新的节点模块(即它位于node_modules/my-reporter/reporter.js中)。但是,我似乎无法让mocha加载这位记者。我尝试了很多变体……mochaallTests.js-R./node_modules/my-reporter/reporter.jsmochaallTests.js-Rmy-reporter但没有任何作用:-(我可以在JS文件
目标:为waCarousel指令范围变量编写一个通过测试:self.awesomeThings。当self.awsomeThings.length.toBe(3)为真时,期望此测试通过?问题:如何正确编写此测试?而是如何注入(inject)指令Controller?指令:angular.module('carouselApp').directive('waCarousel',function(){return{templateUrl:'../../../views/carousel/wa.carousel.html',controller:function($scope){varsel
我正在尝试开始使用karma和Jasmine。我已经安装了它们。我相信Karma可以找到我的JavaScript文件。当我运行karmastart时,我的浏览器打开并显示:Karmav0.12.23-connectedIE11.0.0(Windows8.1)isidleFirefox29.0.0(Windows8.1)isidleChrome37.0.2062(Windows8.1)isidle我将一个JavaScript文件添加到我认为Karma正在监视的位置:it('yshouldhavealengthof1',function(){vary='1';expect(y.length
我有一个奇怪的问题。每当我尝试测试某些东西但测试失败时,它总是显示第9行的堆栈跟踪。我正在使用AngularJS以及Jasmine和Karma。我发现它不依赖于浏览器。错误如下所示:TypeError:'undefined'isnotanobject(evaluating'newgoogle.maps.LatLng')at/Users/user1/project1/test_ctrl.js:9at/Users/user1/project1/spec/test_ctrl_spec.js:170因此,它告诉我测试在第170行失败(这是正确的),但错误原因在我的test_ctrl.js中,行
当两者都是对象数组时,断言预期结果与实际结果相匹配的最佳方法是什么?我的直接想法是使用Array原型(prototype)过滤器并检查交集是否与预期的大小相同,即:describe('select',function(){it("shouldreturnselectedcolumns",function(done){varquery="selectlunchTime,name";varactual=...resultsofthequery,anarrayofanonymousobjects...//expectedresultsvarexpected=[{"lunchTime":"12
我有一个要测试的简单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