Async is a Best Practice
Originally released in the third border of the Institute szhshp , please indicate
关键字: Jest with multiple async, Jest nested async
Remember this place Do not use nested the Test , use beforeAll () instead of
DO NOT USE nested test !!!
Use
beforeAll()
instead
DESCRIBE ( 'the Delete the User', () => { the let XID; // Sometimes we need to extract some preliminary data from the database beforeAll (() => { axios.get ( `$ {Domain} graphQL Query = {? getUser (username: "$ {} testAccount.username", password: "123456789") { errors Success the _id } } `) .then (RES => res.data.data.getUser) .then ((RES) => { XID = res._id; // set it to a local variable, then the variable can be used below a }); }); Test ( 'the Get the User: Wrong ID', () => axios.post ({$ `Domain graphQL`}, { Query: `{mutation deleteUser (the _id:" 5d0ef90a36ae0b798cd11111 ") { # wrong id here errors) { # wrong id here success } }`, }) .then(res => res.data.data.deleteUser) .then((res) => { expect(res.success).toEqual(false); expect(res.errors).toEqual([ERRORS.USER.USER_NOT_FOUND]); })); test('Get User: Correct Inputs', () => axios.post(`${domain}graphQL`, { query: `mutation{ deleteUser(_id: "${xid}") { errors success } }`, }) .then(res => res.data.data.deleteUser) .then((res) => { expect(res.success).toEqual(true); expect(res.errors).toEqual([]); })); });