草庐IT

test_should_do_something_really_s

全部标签

ruby - Ruby 中有 "do ... while"循环吗?

我使用此代码让用户输入名称,同时程序将它们存储在数组中,直到他们输入一个空字符串(他们必须在每个名称后按回车键):people=[]info='a'#mustfillvariablewithsomething,otherwiseloopwon'texecutewhilenotinfo.empty?info=gets.chomppeople+=[Person.new(info)]ifnotinfo.empty?end这段代码在do...while循环中看起来会好得多:people=[]doinfo=gets.chomppeople+=[Person.new(info)]ifnotinfo

javascript - Should.js:检查两个数组是否包含相同的字符串

我有两个数组:vara=['a','as','sa'];varb=['sa','a','as'];shouldJS有什么特别的东西可以测试这两个数组是否有相同的项目?什么都喜欢should(a).be.xyz(b)那可以测试它们吗?在这里,xyz是我正在寻找的。 最佳答案 一个简单但可能足够的解决方案是在比较数组之前对数组进行排序:should(a.sort()).be.eql(b.sort())请注意sort()worksin-place,改变原始数组。 关于javascript-Sh

javascript - JS : What do the curly braces inside function parameter declarations mean?

这个问题在这里已经有了答案:Whatdocurlybracesinsideoffunctionparameterlistsdoines6?(3个答案)关闭4年前。我一直在关注thistutorial在使用Redux设置React时,我注意到一些我不熟悉的语法。函数参数定义里面的花括号是干什么的?例子:functionStream({tracks=[],onAuth}){#whatisgoingonhere?return(...#componentstuffhere);}这是React特有的吗?还是这与Babel或其他图书馆有关?我是这项技术的新手,所以不确定发生了什么。

JavaScript 约定 : How do you assign arguments to the parent scope

varproblemtest=function(){varparameters;returnfunction(parameters){parameters=parameters;}}varmysolutiontest=function(){varparameters;returnfunction(parametersIn){parameters=parametersIn;}}这更像是一个JavaScript约定问题。通常我在上面有类似的代码。函数接受参数并将其分配给父范围。但是,我不能像在problemtest中那样使用它,因为作为参数的parameters隐藏了problemtest

javascript - 类型错误 : parsed is undefined on angularjs service unit test

我正在尝试对使用$http的服务进行单元测试。我正在使用Jasmine,但我一直收到此错误:TypeError:parsedisundefinedinangular.js(line13737)这是我的服务的样子:angular.module('myapp.services',[]).factory('inviteService',['$rootScope','$http',function($rootScope,$http){varinviteService={token:'',getInvite:function(callback,errorCallback){$http.get('

javascript - Node + xmldom : How do I change the value of a single XML field in javascript?

使用nodev.0.10.29,Expressv4.12.0和xmldomv0.1.19,我正在尝试执行以下操作:步骤将XML文件读入字符串使用xmldom将字符串转换为XML对象设置default字段到test将XML对象转换回字符串问题问题是在我设置之后字段,它在对象中正确设置,但是当我将它转换为字符串时,字段恢复为旧值(错误)。代码代码如下所示:varfs=require('fs');varDOMParser=require('xmldom').DOMParser;varXMLSerializer=require('xmldom').XMLSerializer;varfilena

javascript - 如何在 mocha 中使用 should() 的 OR 条件

我想使用两个值进行比较,这样如果其中一个为真,那么我的测试应该通过。使用下面的代码只是比较第一个条件并且测试失败。if(typeoflng!=='undefined'){data.lng.should.equal(lng)||data.cityLng.should.equal(lng);我应该怎么做? 最佳答案 试试这个:if(typeoflng!=='undefined'){lng.should.be.equalOneOf(data.lng,data.cityLng);参见documentation.

javascript - typeof something 返回对象而不是数组

x是一个数组。我做console.log(x)我有['value']但是当我检查类型为console.log(typeofx)的x时,它说它是一个对象。为什么? 最佳答案 数组是JS中的对象。如果你需要为数组测试一个变量:if(x.constructor===Array)console.log('itsanarray'); 关于javascript-typeofsomething返回对象而不是数组,我们在StackOverflow上找到一个类似的问题: htt

javascript - Node : Testing with sinon and async/await

使用sinon和async/await运行此测试时遇到问题。这是我正在做的一个例子://infilefuncsasyncfunctionfuncA(id){leturl=getRoute53()+idreturnawaitfuncB(url);}asyncfunctionfuncB(url){//emptyfunction}和测试:letfuncs=require('./funcs');...//describeletstubRoute53=null;letstubFuncB=null;letroute53='https://sample-route53.com/'letid='123

javascript - React-testing-library:因输入而改变

我正在尝试测试组件是否会因输入元素的更改而更新。我使用fireEvent.change()函数,如果我随后检查我使用getByPlaceholderText找到的节点的值,它已按预期更新。但是我看不到react组件本身的变化。这可能是因为更改直到重新渲染才会发生;我将如何测试这个?react-testing-library的rerender似乎“从头开始”启动组件(即没有新的输入值),并且waitForElement永远找不到它在等待什么。这是组件TestForm.js:importReactfrom'react';import{withState}from'recompose';co