草庐IT

test_method

全部标签

javascript - 为什么连续调用 `pattern.test(name)` 结果相反

这个问题在这里已经有了答案:WhydoesaRegExpwithglobalflaggivewrongresults?(7个答案)关闭7年前。为什么这段代码先返回true,然后返回falsevarpattern=newRegExp("mstea",'gi'),name="AmandaOlmstead";console.log('1',pattern.test(name));console.log('1',pattern.test(name));演示:Fiddle

javascript - Firefox 异常 'JavaScript component does not have a method named: "可用"'

我正在使用Django构建网络应用程序。我通过Ajax(jQueryv1.8.3)在Javascript中调用了一堆API。它们中的大多数都有效,但有一个特定的结果会返回一个状态为0的对象,并将此消息作为状态文本:[异常...“'JavaScript组件没有名为:'available''调用方法时:[nsIInputStream::available]”nsresult:“0x80570030(NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED)”location:“JSframe::http://127.0.0.1:8000/media/js/jq

Javascript 正则表达式.test() "Uncaught TypeError: undefined is not a function"

只是尝试通过.test()函数使用javascript的正则表达式功能。varnameRegex='/^[a-zA-Z0-9_]{6,20}$/';if(nameRegex.test($('#username').val())){...}错误在这一行if(nameRegex.test($('#username').val())){调试器在那里中断并说“UncaughtTypeError:undefinedisnotafunction”。好像.test()没有定义?不应该吗? 最佳答案 就目前而言,nameRegex不是正则表达式而是

javascript - 守夜人 : Better way than `.pause(1000)` to avoid brittle tests?

.pause(1000)真的是等待表单提交的最佳实践吗?我正在寻找一种可靠地提交表单的方法,而无需知道作为表单提交结果出现的页面的详细信息。例子来自homepage使用.pause(1000)等待表单提交,具有讽刺意味的是不再起作用,但是这个带有修改后的css-selector版本的版本可以:module.exports={'DemotestGoogle':function(client){client.url('http://www.google.com').waitForElementVisible('body',1000).assert.title('Google').asser

JavaScript 模块模式 : How do private methods access module's scope?

在实现模块模式时,私有(private)函数如何访问模块的私有(private)属性?我还没有看到开发人员这样做的任何例子。有什么理由不这样做吗?varmodule=(function(){//privatepropertyvarnumber=0;//privatemethod_privateIncrement=function(){//howdoIaccessprivatepropertieshere?number++;};//publicapireturn{//OKgetNumber:function(){returnnumber;},//OKincrNumber:function

JavaScript 面向对象 : method definition with or without "prototype"

是这段代码吗,functionPerson(){functionmyMethod(){alert('hello');}this.method=myMethod;}相当于:functionPerson(){}Person.prototype.method2=function(){alert('hello');};如果是,我应该使用哪个方法定义,为什么? 最佳答案 在您的简单示例中,它们在功能上是等效的,但在幕后的工作方式却大不相同。函数的prototype属性实际上是“原型(prototype)模板”。它说“每当创建一个对象并且我被用

javascript - 有什么方法可以避免使用 JSDoc "@method"注释

我个人不是生成文档的忠实拥护者(我更像是一个“阅读源代码Luke”的人),但我可以看到此类文档对其他人有何用处。现在,通常他们生成的文档不会影响我,除了一件事:@method。大多数JSDoc注释(例如@param)对于阅读源代码的人来说仍然非常有用,但是@method是100%冗余的:/**@paramnumnumbertoaddfiveto*@methodaddFive*/functionaddFive(num){...所以,我真的很想避免让数百行@method弄乱我们的代码。但是,我的同事认为@method是JSDoc生成器(他使用的是YUI生成器)能够生成类的方法列表所必需的。

javascript - Internet Explorer 11 : Object doesn't support property or method 'isInteger'

我在InternetExplorer控制台中遇到此错误“对象不支持属性或方法‘isInteger’”,我该如何解决?代码:functionverificaNota(nota){if(nota.length>0){vararr=[];if(nota.indexOf(".")!=-1){returnferificareArrayNote(nota.split('.'));}elseif(nota.indexOf(",")!=-1){ferificareArrayNote(nota.split(','));}elseif(nota.length0){returntrue;}else{retu

javascript - 类型错误 : Cannot call method 'then' of undefined Angularjs

我是Angular的新手,在进行同步操作时遇到了问题。我已经解决了AngularController出现的几个问题,我从newController文件中得到错误“无法调用未定义的方法”。angular.module('newApp.newController',['angularSpinner','ui.bootstrap']).controller('newController',function($q,$scope,utilityFactory,$http){utilityFactory.getData().then(function(data){console.log("succ

javascript - Jest : Testing window. location.reload

如何编写测试以确保方法reloadFn实际上重新加载窗口?我找到了thisresource但是我不清楚在给定函数中发生窗口重新加载时编写测试时如何期望窗口重新加载。感谢您的帮助!constreloadFn=()=>{window.location.reload(true);} 最佳答案 更新答案(2021年11月)包装:“开Jest”:“^26.6.0”"@testing-library/jest-dom":"^5.11.4"构建:create-react-app4describe("testwindowlocation'srelo