草庐IT

javascript - Jasmine 期待(结果代码)。toBe(200 或 409)

对于某些测试场景,我遇到了针对多个值进行测试的需求,这些值都可以。我想做的事情如下:expect(resultCode).toBeIn([200,409]);当resultCode为200或409时,该规范应该通过。这可能吗?已添加感谢peter和dolarzo指导我创建匹配器。我在使用addMatchers()时遇到了问题。所以,最后我在jasmine.js中添加了以下内容:jasmine.Matchers.prototype.toBeIn=function(expected){for(vari=0;i这给了我一个可行的解决方案。我现在可以根据需要执行toBeIn。(Jasmine1

javascript - $browser.$$checkUrlChange 在 Jasmine 测试中未定义

我有以下测试:it('shouldmaintainabindbetweenthedataatthe$scopetothedataattheingredientsService',function(){$scope.addFilters('val1',$scope.customFiltersData,'filter1');$scope.$digest();expect($scope.customFiltersData).toEqual(ingredientsService.filters());});我收到以下错误:TypeError:undefinedisnotafunctionatS

javascript - 当不同文件中存在测试时,如何在 jasmine 中对测试套件进行分组?

根据文档,我们可以有测试套件的组-子组,但它们只存在于一个文件中,如下所示describe('MainGroup-Module1',function(){beforeEach(function(){module('app');});describe('subgroup-1',function(){//Subgroup//specsgoeshere});describe('subgroup-2',function(){//Subgroup//specsgoeshere});});如果我想将subgroup-1和subgroup-2保存在两个不同的文件中,我如何将这两个子组分组到MainG

javascript - 试图监视(Jasmine)Array.prototype 方法导致堆栈溢出

这很奇怪。将testemrunner与jasmine2一起使用并执行以下规范(尽管它正确地标记了没有期望):describe('Spyingonarray.prototypemethods',function(){it('shouldworkthisway',function(){spyOn(Array.prototype,'push').and.callThrough();//expect(1).toBe(1);});});但是,添加一个expect(任何expect!)它会导致堆栈溢出,并在testem控制台中显示以下消息:RangeError:超出最大调用堆栈大小。在http:/

javascript - 将 Jasmine JavaScript 单元测试与 TFS Build CI 集成的简便方法

我一直在使用Jasmine编写JavaScript单元测试。但是,这些测试在浏览器中运行,而不是作为MSTest的一部分。我希望我的TFS持续集成构建在JavaScript单元测试失败时中断。我知道VisualStudio2012中有针对此问题的解决方案,但我在2010年(并且可能在未来很长一段时间内)。有没有一种简单的方法可以将基于Jasmine的JavaScript单元测试与TFSBuild集成? 最佳答案 Chutzpah测试运行器使您能够从命令行或VisualStudio运行QUnit和JasmineJavaScript单元

javascript - 如何从 Jasmine 测试 Angular 2/4 触发文档级事件

根据Angular测试文档,要从测试中触发事件,我们在调试元素上使用triggerEventHandler()方法。此方法采用事件名称和对象。现在,如果我们使用HostListener添加事件,这将起作用。例如:@HostListener('mousemove',['$event'])或添加一个document级别的事件,我们这样做是这样的@HostListener('document:mousemove',['$event']).在我当前的指令实现中,由于我无法嵌套HostListeners,我使用document.addEventListener添加document级事件到Host

javascript - Jasmine 2.0 TeamCity 记者

使用teamcity、requirejs和运行phantomjs.exe的jasmine1.3构建了一个有效的CI,我正在尝试将jasmine升级到2.0版。在这篇精彩的文章之后,我得到了一个基本的htmlspecrunner页面。(Jasmine现在加载到windows.onload,https://stackoverflow.com/a/20851265/564577)现在我正在尝试让teamcity-reporter工作。(来自测试框架下的插件页面,http://confluence.jetbrains.com/display/TW/TeamCity+Plugins#)它依赖于j

javascript - 使用 Jasmine 对 $modal 进行单元测试

我有一个带有Controller的Angular应用程序,它在函数调用期间显示Angular-Strap模态窗口。它在Chrome中正常运行,但我无法进行有效的单元测试。App模块和FooController:varapp=angular.module("app",["mgcrea.ngStrap"]);app.controller("FooController",function($scope,$modal){varfooModal=$modal({title:'Foo',content:'Bar',show:false,html:true,backdrop:'static',pla

javascript - 使用 Jasmine 测试异步回调

我正在使用Jasmine2.1。我正在尝试使用Jasmine2.1来测试模块。我的模块之一具有异步执行代码的功能。当应用程序完成执行时,我需要测试函数的结果。有没有办法做到这一点?目前,我的模块看起来像这样:varotherModule=require('otherModule');functionMyModule(){}MyModule.prototype.state='';MyModule.prototype.execute=function(callback){try{this.state='Executing';varm=newotherModule.Execute(funct

javascript - Jasmine jQuery : Check if element is visible

你好,我有一个关于使用Jasmine(插件:jQuery)进行单元测试的问题我如何测试对象是否在文档的DOM中。问题是我使用了一个工具提示功能,只有在模拟事件时才会激活。当有模拟效果时,一个对象被附加到DOM上,我想检查它是否可见。it("test1:shouldinvoketheTooltip()function.",function(){spyEvent=spyOnEvent('.span_width',"mouseover");$('.span_width').simulate('mouseover');expect('mouseover').toHaveBeenTriggere