草庐IT

jest-jasmine

全部标签

javascript - 在 Jasmine 测试中 stub e.preventDefault()

我最近在我的一个javascript函数中添加了一个e.preventDefault(),它破坏了我的jasmine规范。我试过spyOn(e,'preventDefault').andReturn(true);但我得到eisundefined错误。如何stube.preventDefault()?showTopic:function(e){e.preventDefault();midParent.prototype.showTopic.call(this,this.model,popup);this.topic.render();}it("callstheparent",functi

javascript - 开 Jest , enzyme - 测试返回 jsx 的方法

我有以下组件:importReact,{Component}from'react';import{Link,IndexLink}from'react-router';classNavbarextendsComponent{renderLinks=(linksData)=>{returnlinksData.map((linkData)=>{if(linkData.to==='/'){return({linkData.icon}{linkData.text})}else{return({linkData.icon}{linkData.text})}})};render(){return({

javascript - Jest 匹配器匹配三个值中的任何一个

我的组件中有这个选择器,它的默认状态是''(空)字符串,但是当change事件被触发时,用户可以选择三个值中的任何一个是6、12还是24it("feedformtestingtheselectorfeedfrequencyforvalueof6,12,24",()=>{constaddFeedForm=shallow({}}setFeedData={()=>{}}formType="add"feedsubmit={{status:null,error:{formsubmitwarning:"",feedname:"",feedurl:"",feedposttype:"",feedfre

javascript - 使用 Jasmine 2.0 对 $scope.$evalAsync 函数进行单元测试

我正在尝试对$scope.$evalAsync函数进行单元测试。这是我的代码:$scope.$evalAsync(function(done){//enablethepopoverplugindone();jQuery('[data-toggle="popover"]').popover();$scope.isKioskIdLoaded.state=true;});我很难理解如何让evalAsync在我的Jasmine测试中运行。我正在尝试利用Jasmine2.0中的done()函数。 最佳答案 您需要将$scope.$digest

javascript - 如何使用 Jasmine 在 AngularJS 中为数组函数创建单元测试

我有xf数组:varxf=[];我有一个函数是这个数组中的一个元素和一个使用它的函数:$scope.checkEmailValid=function(){varresult=false;Iif(xf.validateEmail($scope.email,'256')){result=true;}returnresult;};xf.validateUsername=function(sText){varisValid=false;do{//Checkforvalidstring.isValid=typeofsText==='string';if(!isValid){break;}//Ch

javascript - Jasmine:为 Rails 定义单独的源文件集?

我网站的不同部分有不同的Javascript文件集,它们-一起扔在一起-相互干扰。为了用Jasmine测试一切,我似乎需要一些方法来为不同的套件定义单独的“Assets”集。这目前是否可能,如果可能,如何实现? 最佳答案 您可能需要按照建议考虑将您的javascript分成不同的命名空间。使将javascript分成多个文件变得容易的一种好方法是使用modulepattern它使用闭包和javascript的一些其他简洁属性来立即执行必要的代码,并将其包含在内。 关于javascript

javascript - 为什么 Jasmine spy 不认为它被调用,即使它返回了 andReturn 值?

我正在尝试调试jQuery.post上的spy程序那没有开火,所以作为完整性检查,我试过了spyOn(this.viewModel.requests,'submitRequest').andReturn('fooz');varret=this.viewModel.requests.submitRequest();expect(ret).toEqual('foo');expect(this.viewModel.requests.submitRequest).toHaveBeenCalled();这失败了Expected'fooz'toequal'foo'.但是当我在andReturn的参

javascript - 我不能用 Jest 运行多个测试文件?

我今天才开始使用Jest。我的__tests__目录中有一个简单的测试文件。这是当前的测试文件:describe('ChangeCalendarView',function(){it('true',function(){expect(3).toBe(3);})});这运行没有问题。当我添加另一个文件时,除了描述之外,代码完全相同:describe('ChangeTimePeriod',function(){it('true',function(){expect(3).toBe(3);})});然后我得到这个错误:/usr/local/lib/node_modules/jest-cli/

javascript - 如何使用 Jest 测试 void javascript 函数?

如何使用jest框架测试voidjavascript函数(一个不返回任何内容的函数)?您能否提供相同的示例?/***thisfunctionisusedtotoggletheinputtypepasswordfield*@paramelement{DOMElement}-fieldtobetoggled*/exportconsttogglePassword=(element)=>{consttype=element.getAttribute('type');if(type==='text'){element.setAttribute('type','password');}else{e

javascript - Karma + Jasmine( Angular Testing ): Where should I define mock classes and test variables?

让我们来看下面的例子:constlistDefinition:any={module:"module",service:"service",listname:"listname"};@Component(...)classMockTreeExpanderComponentextendsTreeExpanderComponent{...}classMockListConfigurationsServiceextendsListConfigurationsService{...}describe('ColumnsListConfigurationsComponentTestcases',(