Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass variable from beforeEach hook to tests in jest?

Tags:

jestjs

beforeEach(async () => {   const sandbox = sinon.sandbox.create()   ... })  test('/add', () => {   // how can I use sandbox here? }) 

What I need is something like t.context in ava

like image 677
wong2 Avatar asked Sep 19 '18 03:09

wong2


1 Answers

Just declare sandbox so it is available in the scope of beforeEach and test:

let sandbox;  beforeEach(async () => {   sandbox = sinon.sandbox.create()   ... })  test('/add', () => {   // sandbox available for use }) 
like image 80
Brian Adams Avatar answered Sep 29 '22 13:09

Brian Adams