草庐IT

jasmine-core

全部标签

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

javascript - Protractor/Jasmine2 - 在指定超时内未调用异步回调

我在selenium网格上运行的e2e测试遇到了问题。有时测试失败是因为Error:Timeout-Asynccallbackwasnotinvokedwithintimeoutspecifiedbyjasmine.DEFAULT_TIMEOUT_INTERVAL.试图以某种方式解决它,将defaultTimeoutInterval更改为protracotr.conf.js中的更高值,但结果等待时间更长,但错误是相同的。exports.config={chromeOnly:true,chromeDriver:'../node_modules/.bin/chromedriver',fra

javascript - 如何在规范文件中注入(inject)服务 Angular Testing (Jasmine/karma)

我刚开始编写Angular单元测试用例。我在我的Controller文件(.ts)中注入(inject)一项服务。我将如何在规范文件中注入(inject)服务文件。代码如下:app.component.tsgetSortData(){this.sortService.sortNumberData(this.data,'name','asce');}sort.service.tssortNumberData(data,rendererKey,type){//data.sort((elem1,elem2)=>{////ifnumberisundefined,thenassigning`MA

javascript - 如何测试该方法是否已在 Jasmine 中调用?

我对监视Jasmine有点困惑。我有这样的代码,但我不确定如何测试它。varparams={param1:"",param2:"link",param3:"1",param4:"1"};varfunc=newmyFunction(params);func.doSomething();如何测试func.doSomething已被调用。这是我到目前为止写的测试describe("Library",function(){beforeEach(function(){});it("shouldincludecorrectparameters",function(){expect(params.p

javascript - 在 jasmin 中使用测试 Angular 复选框

我的情况如下:指令scope:{foo:'='},template:''父Controller$scope.foo=false;Jasmine测试varcb=iElement.find('input');$timeout(function(){//using$timeouttoensure$digest()isn'ttheissue.cb.prop('checked',!cb.prop('checked'))},0);expect(cb.prop('checked')).toBe(true);//passesexpect($scope.foo).toBe(true);//doesn't

javascript - ASP.NET Core 2.1 SignalR 未定义

这是我的聊天javascript"usestrict";varconnection=newsignalR.HubConnectionBuilder().withUrl("/chathub").build();connection.on("ReceiveMessage",function(message){varmsg=message.replace(/&/g,"&").replace(//g,">");varencodedMsg=msg;varli=document.createElement("li");li.textContent=encodedMsg;documen

javascript - 使用 Jasmine 在 Karma 中进行 AngularJS 工厂测试

我正在尝试通过Karma使用Jasmine测试我的AngularJS应用程序。我收到此错误(至少,这是最新的错误):UncaughtTypeError:Cannotreadproperty'$modules'ofnullat/Users/benturner/Dropbox/Code/galapagus/app/static/js/angular-mocks.js:1866来self的karma.conf.js:files:['static/js/jquery.min.js','static/js/angular.min.js','static/js/angular-mocks.js',

javascript - 如何在 Jasmine 中比较两个具有浮点值的对象?

我需要在Jasmine中做一些期望,比如:letrealValue=callSomeMethod();letexpected=[{total:33,saved:1.65}];expect(realValue).toEqual(expected);但是它失败了,消息是:Expect[Object({total:33,saved:1.6500000000000001})]toequal[Object({total:33,saved:1.65})].如何进行正确的检查? 最佳答案 toBeCloseTo匹配器用于精确数学比较:expect