chai expect async function to throw asyncfunctionexpectthrow()sinon-StackOverflow,AsyncAwaitthrowanerrorinMocha-StackOverflow,chaiexpectasyncthrowCodeExample-codegrepper,expect(awaitfn())vsawaitexpect(fn())forerrortestswithchai...,HowtotestanES7asyncfunction·Issue#415·chaijschai...,Mocha&Chai-TestifasyncfunctionthrowsTypeErrorwhen...,node.js:使用MochaChai和asyncawait驗證是否丟擲異常...,Testasyncfunctiontothrowwithmocha-StackOverflow,UsingChaiexpectthrownotcatchingpromiserejection...,VerifythatanexceptionisthrownusingMochaChaia...
2015年4月3日 — throw ) throws the error in the it() scope. That would explain why a try catch works but an expect(...) doesn't. Any thoughts?2020年4月21日—Ifyouonlyusechai,chaidoesn'tsupportasserterrorthrowninasynchronousfunctions.Instead,youcanusetry/catch+async/await.
Thewayyouhavesetupthethetestwon'tworkbecauseexpect.to.throwisnotexpectingapromise.AtleastIthinkthatiswhatisgoingonbasedonthisissue.
2020年7月3日—constchai=require('chai')constexpect=chai.expectchai.use(require('chai-as-promised'))//Alwayssucceedsasyncfunctionwins()return ...
constsomeFn=async()=>thrownewError(`I'manerror!`)}Andhere'sourtestsetupusingChai/chai-as-promised:constchai=require ...
2020年7月21日—it('throwsTypeErrorwhenaliasparamisnottypeof"string"',async()=>awaitexpect(aliasIsAdmin()).to.be.rejectedWith(TypeError);});.
2019年8月22日—在使用async/await時,我正在努力找出在Mocha測試中驗證承诺被拒绝的最佳方法....await將拒绝轉換為異常的事實,並將其与Chai的should.throw結合...我只是在使用asyncwins()的功能和fails()和expe...
2018年4月23日—throw()won'tworkasexpected.Itassertsthatapromiseresolveswithafunctionthatwillthrowerrorsynchronouslywhencalled.Thisislikelynot ...
2018年5月18日—expect().to.throw(Error)willonlyworkforsyncfunctions.Ifyouwantasimilarfeatureusingasyncfunctionstakealookatchai-as-promised
2017年8月2日—constchai=require('chai')constexpect=chai.expect...Thereforeyoumustawaittheminthecontextofanasynctestfunction,orelsefailing ...