Fix flaky test

This commit is contained in:
Adria Navarro 2023-02-05 09:04:47 +00:00
parent 6ac57d424c
commit 4522d6c906
2 changed files with 12 additions and 3 deletions

View File

@ -19,11 +19,13 @@ describe("/datasources", () => {
afterAll(setup.afterAll)
beforeEach(async () => {
async function setupTest() {
await config.init()
datasource = await config.createDatasource()
jest.clearAllMocks()
})
}
beforeAll(setupTest)
describe("create", () => {
it("should create a new datasource", async () => {
@ -102,6 +104,8 @@ describe("/datasources", () => {
})
describe("fetch", () => {
beforeAll(setupTest)
it("returns all the datasources from the server", async () => {
const res = await request
.get(`/api/datasources`)
@ -170,6 +174,8 @@ describe("/datasources", () => {
})
describe("destroy", () => {
beforeAll(setupTest)
it("deletes queries for the datasource after deletion and returns a success message", async () => {
await config.createQuery()

View File

@ -3,6 +3,8 @@ const { checkPermissionsEndpoint } = require("./utilities/TestFunctions")
const setup = require("./utilities")
const { BUILTIN_ROLE_IDS } = roles
jest.setTimeout(30000)
jest.mock("../../../utilities/workerRequests", () => ({
getGlobalUsers: jest.fn(() => {
return {}
@ -19,7 +21,8 @@ describe("/users", () => {
afterAll(setup.afterAll)
beforeAll(async () => {
// For some reason this cannot be a beforeAll or the test "should be able to update the user" fail
beforeEach(async () => {
await config.init()
})