在所有测试之前,Jest运行async函数ONCE [英] Jest run async function ONCE before all tests

查看:170
本文介绍了在所有测试之前,Jest运行async函数ONCE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用jest进行服务器单元测试(而不是mocha + chai)。
有没有一种方法可以在所有测试开始(初始化目的)之前运行异步函数,而不是每个测试文件?并且如果在完成所有测试后有一种运行方式吗?

I want to use jest for my server unit testing (instead of mocha+chai). Is there a way I can run async function before all tests start (init purposes) only once and not for every test file? And also if there's a way of running something after all tests are done?

推荐答案

此功能已添加到 Jest的22版本 globalSetup globalTeardown 配置。
查看这个的例子。

This feature was added in Jest's 22 version, with globalSetup and globalTeardown configurations. Look at this for examples.

这篇关于在所有测试之前,Jest运行async函数ONCE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆