草庐IT

test-status

全部标签

javascript - Websocket 错误 : Error during WebSocket handshake: No response code found in status line

我想与我的服务器建立一个tcp连接。但是我每次都会出错...WebSocketconnectionto'ws://my.ip:1337/'failed:ErrorduringWebSockethandshake:Noresponsecodefoundinstatusline:Echoserver客户:varconnection=newWebSocket('ws://my.ip:1337');connection.onopen=function(){connection.send('Ping');//Sendthemessage'Ping'totheserver};服务器:varnet=

javascript - Mocha 测试 : Uncaught TypeError: Cannot read property 'status' of null

学习TDD和我对“HelloWorld”服务器响应的第一个简单测试在Mocha中失败了。我正在使用Mocha.js、Superagent和Expect.js。当我curl-ilocalhost:8080时,我得到了正确的响应和状态代码。HTTP/1.1200OKContent-Type:text/plainDate:Mon,27Apr201517:55:36GMTConnection:keep-aliveTransfer-Encoding:chunkedHelloWorld测试代码:varrequest=require('superagent');varexpect=require('

javascript - Jest : cannot find module required inside module to be tested (relative path)

我有这个组件:importReactfrom'react';importVideoTagfrom'./VideoTag';importJWPlayerfrom'./JWPlayer';classVideoWrapperextendsReact.Component{//...componentcode}基于某些逻辑在内部呈现另一个组件(VideoTag或JWPlayer)但是当我尝试在一个Jest文件中测试它时我得到错误:找不到模块'./VideoTag'这三个组件在同一个目录中,这就是为什么当我转译它并在浏览器中看到它在运行时它实际上有效但看起来Jest在解析这些相对路径时遇到问题,这

javascript - Vue-test-utils:在单个测试中多次使用 $nextTick

我正在为vuelidate编写单元测试在我的组件中进行验证。我发现$touch()方法是异步调用的,所以我需要为expect()使用$nextTick()。当我需要两个nextTick()s用于两个expect()s时,问题就出现了。describe('Validations',()=>{letdataletmyComponentbeforeEach(()=>{data=()=>{propertyABC='notallowedvalue'}myComponent=localVue.component('dummy',{template:'',validations,data})it('

带有 .test() 的 Javascript 正则表达式

>varp=/abc/gi;>vars="abc";>p.test(s);true>p.test(s);false;当我在Chrome的控制台上运行此代码时,上面有此输出。每次调用'.test()'时,我都会得到不同的值。有人可以向我解释为什么会这样吗?谢谢 最佳答案 该行为是由于“g”修饰符,即匹配三次,第四次不匹配:>varp=/a/gi;>vars="aaa";>p.test(s)true>p.test(s)true>p.test(s)true>p.test(s)false查看类似问题:WhyRegExpwithglobalf

javascript - 无法填充名为 `status` 的数组

我正在尝试做一些非常简单的事情——用Javascript初始化一个数组。它在谷歌浏览器中不起作用。这是代码:status=[];for(i=0;i什么给了? 最佳答案 status变量的分配与window.status冲突属性(property)。Chrome只是拒绝进行分配。window.status属性,设置或获取浏览器底部状态栏中的文本。我建议您要么重命名您的变量,要么使用匿名函数来创建新范围,同时记住始终使用var声明变量:(function(){varstatus=[];for(vari=0;i

Javascript Regex 应该通过 .test() 但似乎失败了 - 为什么?

这个问题在这里已经有了答案:WhydoesaRegExpwithglobalflaggivewrongresults?(7个答案)关闭7年前。在javascript中测试我的正则表达式时,我似乎总是得到一个奇怪的结果。这是我的fiddle:http://jsfiddle.net/s5fYf/15/这取self正在构建的网络项目。我将一组验证对象传递到我的验证函数中,该函数遍历它们,根据值验证每个规则。如果一个为假,它应该停止循环并返回一个返回对象,该对象从失败的规则中获取消息和cssClass。问题是即使正则表达式测试通过,验证方法似乎也返回false,这应该是不可能的!所以我觉得我错

javascript - RegExp.test() 根据调用方式(在哪里?)为相同的 str 返回不同的结果

我刚刚注意到一个奇怪的JS行为导致了一个烦人的错误..基本上,我在if语句中使用RegExp对象(.test()方法)测试str。对于相同的测试字符串,如果在我的代码中只有一个if,则regexp.test()返回true并且可以正常进入if。问题是如果我有一个else(我需要它),出于某种原因,对于相同的str测试,regexp.test()返回false并且它转到else...这是什么行为?我已经运行了很多测试...TL/DR:对于在同一个RegExp上测试的同一个字符串,如果只有一个IF语句,则regexp.test()返回true,但如果我有一个else,它返回false。so

javascript - Steam 发布请求 - 无法加载资源 : the server responded with a status of 400 (Bad Request)

我正在尝试发送这样的帖子请求:xhr.open("POST","/steamapi/actions/RemoveFriendAjax",false);varparams="sessionID="+session_id+"&steamid="+id;xhr.onreadystatechange=function(){//Callafunctionwhenthestatechanges.if(xhr.readyState==4&&xhr.status==200){alert(xhr.responseText);}}xhr.send(params);我正在使用Apache服务器,这是我的.h

javascript - Koa 的 `ctx.status` 没有发送给客户端

这是我的简单路线:router.post('/getFile',async(ctx)=>{constfileName=`${ctx.request.body.file}.pdf`;constfile=fs.createReadStream(fileName);//Thisfilemightnotexist.file.on('error',(err)=>{ctx.response.status=500;//Thisstatuscodedoesn'tmakeittoclientwhenthere'sanerror.});ctx.response.type='application/pdf'