[英]Testing js/esm project w/ sinon, nyc and ava - test w/ spy on console fails despite console log
I have an esm
project I'm trying to test with ava
, nyc
and sinon
. 我有一个esm
项目,我正在尝试使用ava
, nyc
和sinon
进行测试。 I have had some success using sinon to spy on console.log and report whether or not it is being called, but on another set of files, where I feel I'm doing the same things, I can't get it to work. 使用sinon监视console.log并报告是否被调用已经取得了一些成功,但是在另一组文件上,我感觉自己在做同样的事情,因此无法正常工作。 I don't know if it's sinon or ava or what is the problem. 我不知道这是sinon还是ava或问题所在。 I made a test repo here . 我在这里做了一个测试仓库。 When you run npm run test
it will fail and say console.log was not called, but you can see at the top of the output a statement was logged. 当您运行npm run test
,它将失败并说未调用console.log,但是您可以在输出的顶部看到已记录一条语句。 What am I doing wrong? 我究竟做错了什么?
Thank you! 谢谢!
main()
is asynchronous and you only call console.log()
after awaiting. main()
是异步的,只有在等待后才调用console.log()
。 At that point you've already torn down the spy. 到那时,您已经拆除了间谍。 Use await main()
and make the test implementation asynchronous as well. 使用await main()
并使测试实现也异步。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.