jeudi 7 novembre 2019

Jest beforeEach/afterEach just the blocks in this scope?

I want to do something like this:

let database; 
beforeEach(() => {
   database = initDatabase(); 
}); 

afterEach(() => {
   clearDatabase(database); 
}); 


describe("Create and update user test suite", () => {
   let user; 
   it("Post a new user returns a user", async () => {
        const initUser = {/*...*/}; 
        user = await createUser(initUser); 
        //expect... 
   }); 

   it("Modify the user returns the modified user", async () => {
       user = await modifyUser({...user, ...{/*...*/}); 
       //expect...
   }); 

}); 

describe ("Create and update business test suit", () => {
   let business; 
   //it... 
}); 

That is, I want to retain the database state from test to test within the describe block, and then clear it down at the end the describe block.

But the way this code would work is that it would init and clear down after each test, which isn't what I want.

I could just put all the expects into one single test, but then I'd lose visibility of exactly which part of the test is failing.

What would the best way to handle this be?

Aucun commentaire:

Enregistrer un commentaire