I using Jest to run tests.
I am starting a test server which uses tests table to do data insertion and read. So what I am trying to achive is first check in the beforeAll if the running environment is test or not as when I will deploy on server so that it won't run tests in the production db if some mistakes are there and the sever is not test server.
So for this I have a an endpoint which gives the environment and I want to call that endpoint in beforeAll and then if the environment is test continue and execute the test cases other wise I don't want to run the test cases.
How can I acvieve this in Jest?
Below is the code I want to run but return or throw or process.exit nothing is exiting the test cases and all of the tests runs.
beforeAll(async () => {
const GET_ENVIRONMENT_QUERY = gql`
query GetEnvironment {
getEnvironment
}
`;
const loggedInClient = createApolloClientInstance("LOGGEDIN");
const response = await loggedInClient.query({
query: GET_ENVIRONMENT_QUERY,
});
if (response.data.getEnvironment !== "TEST_") {
console.log("Here it should exit");
return;
}
});