jjzjj

catch-unit-test

全部标签

javascript - 简单的 Angular Testing 失败($injector :unpr Unknown Provider) when I have no dependencies

我得到thiserror。这与我的注入(inject)器无法解决所需的依赖关系有关,但即使我对Angular了解有限,我也很确定这段代码不应该依赖于任何模块。此代码在浏览器中运行良好,但它似乎不想在我的测试中运行。我一直在关注文档中的examples我的Angular版本是1.2.13(编辑:现在使用1.12.15)。这是我的代码:varapp=angular.module('app',[]).controller('GreetingCtrl',function($scope){$scope.title="HelloWorld!";$scope.message="Test,test.O

javascript - 如何根据以下内容决定哪个 promise 执行 then/catch

全部:我是Promise的新手,这里有一个例子:varsomeAsyncThing=function(){returnnewPromise(function(resolve,reject){//thiswillthrow,xdoesnotexistresolve(x+2);});};varsomeOtherAsyncThing=function(){returnnewPromise(function(resolve,reject){reject('somethingwentwrong');});};someAsyncThing().then(function(){returnsomeO

javascript - promise .catch() : how to identify the differences between operational rejects and programmatical throws

经过大量谷歌搜索后,我无法找到一个明确的示例,说明如何避免对每个catch进行编程以确定Promise拒绝错误是程序性错误还是操作性错误。将此与提供callback(error,params...)的Node回调模式进行比较,在error参数中明确提供操作错误,并通过抛出链处理编程错误。请告诉我我犯了一个菜鸟错误,对此我错过了一个简单的答案。编辑Nodev10.0.0现在通过添加错误代码解决了这个问题。感谢RisingStack将此发送到我的收件箱:https://blog.risingstack.com/node-js-10-lts-feature-breakdown...正式但相当

javascript - 为什么我得到 'There is no timestamp for/base/src/tests/core/types.tests!' ?

这个问题在这里已经有了答案:karmaerror'Thereisnotimestampfor'(9个回答)关闭6年前。我花了几个小时想弄明白,我想这与我配置错误的requirejs文件(“test.main.js”)有关,但我不太确定,所以有人可以向我解释一下吗怎么了?如果您需要我提供更多信息,我很乐意提供。这是堆栈跟踪的输出。EyalShilony@LIONKING/d/Projects/Code/Development/tsToolkit$./karma.shstartINFO[karma]:Karmav0.12.16serverstartedathttp://localhost:

javascript - 为什么我的 jest.mock 中的 Promise reject() 会转到 then() 而不是 catch()?

我有两个文件,getItemInfo.js进行API调用,getItemInfo.test.js是相应的Jest测试文件。在测试文件中,我正在模拟由Node模块request-promise触发的http调用。问题在第二个代码块上,被*********包围。基本上为什么reject()错误仍然会在第二个单元测试中进入then()block?//getItemInfo.jsconstrp=require('request-promise');constgetItemInfo=(id)=>{constroot='https://jsonplaceholder.typicode.com/po

javascript - TypeScript/Angular try catch,try block 中的任何错误都不会捕获 block

我正在使用Angular和TypeScript。我已经使用trycatch构造在API调用的情况下进行错误处理。如果在tryblock中发生任何错误,它根本不会进入catchblock。应用程序仅在那里终止。我也尝试过使用throw。这是一个示例代码片段,try{this.api.getAPI(Id).subscribe(//this.apiismyapiserviceandgetAPIispresentthere(data:any)=>{if(data==null){throw'Emptyresponse';}},(error:HttpErrorResponse)=>{console

javascript - 你如何冒出错误,以便它们可以在同一个 try/catch block 中被捕获?

我有一个带有抛出错误的函数的对象,myObj={ini:function(){this.f();},f:function(){thrownewError();}};但我只想捕获创建对象的异常try{varo=newmyObj();}catch(err){alert("error!");}看起来我必须到处都有try/catchblock=/以捕获不同函数范围内的错误事件try{myObj={ini:function(){try{this.f();}catch(err){alert("fthrewanerr");}},f:function(){thrownewError();}};}cat

javascript - 我可以在异步函数的 try/catch block 中使用多个 'await' 吗?

即asyncasyncfunction(){try{awaitmethod1();awaitmethod2();}catch(error){console.log(error);}}给定method1()和method2()是异步函数。每个await方法都应该有一个try/catchblock吗?有没有更简洁的方式来写这个?我试图避免“.then”和“.catch”链接。 最佳答案 当等待在await一元运算符右侧创建的promise时,使用一个包含多个await操作的try/catchblock很好:await运算符存储其父asy

Javascript : Insane boolean test with '!' operator

这个问题在这里已经有了答案:Checklegalcharactersbyregularexpressionbutwithunexpectedresult(2个答案)关闭7年前。在chrome控制台中输入以下函数调用:(function(regex,str){console.log(regex.test(str))console.log(!regex.test(str))console.log(!regex.test(str))console.log(!regex.test(str))console.log(!regex.test(str))})(newRegExp("new","gmi

javascript - 它是 Ecmascript 中的错误 -/\S/.test(null) 返回 true 吗?

在Actionscript3和Javascript中,这些语句给出相同的结果:/\S/.test(null)=>true/null/.test(null)=>true/m/.test(null)=>false/n/.test(null)=>true在这种情况下,null值似乎被转换为字符串“null”。这是Ecmascript中的已知错误还是我遗漏了什么? 最佳答案 这不是错误,但你是对的,null强制到'null'并且该行为在规范中定义:RegExp.prototype.test(string),在内部等效于表达式:RegExp.