1
0
Fork 0
mirror of synced 2024-09-20 19:33:10 +12:00

Adding expect function to allow undefined.

This commit is contained in:
mike12345567 2024-08-09 13:39:47 +01:00
parent 97919821ac
commit a9acc7f87b
2 changed files with 8 additions and 10 deletions

View file

@ -1,5 +1,5 @@
import * as setup from "./utilities" import * as setup from "./utilities"
import { checkBuilderEndpoint } from "./utilities/TestFunctions" import { checkBuilderEndpoint, allowUndefined } from "./utilities/TestFunctions"
import { getCachedVariable } from "../../../threads/utils" import { getCachedVariable } from "../../../threads/utils"
import { context, events } from "@budibase/backend-core" import { context, events } from "@budibase/backend-core"
import sdk from "../../../sdk" import sdk from "../../../sdk"
@ -26,14 +26,6 @@ import { tableForDatasource } from "../../../tests/utilities/structures"
import nock from "nock" import nock from "nock"
import { Knex } from "knex" import { Knex } from "knex"
function fetchedSchemaProps() {
return {
externalType: expect.toBeOneOf([expect.any(String), undefined, null]),
constraints: expect.toBeOneOf([expect.anything(), undefined, null]),
autocolumn: expect.toBeOneOf([expect.anything(), undefined, null]),
}
}
describe("/datasources", () => { describe("/datasources", () => {
const config = setup.getConfig() const config = setup.getConfig()
let datasource: Datasource let datasource: Datasource
@ -397,7 +389,9 @@ describe("/datasources", () => {
(acc, [fieldName, field]) => { (acc, [fieldName, field]) => {
acc[fieldName] = { acc[fieldName] = {
...field, ...field,
...fetchedSchemaProps(), externalType: allowUndefined(expect.any(String)),
constraints: allowUndefined(expect.any(Object)),
autocolumn: allowUndefined(expect.any(Boolean)),
} }
return acc return acc
}, },

View file

@ -184,3 +184,7 @@ export const runInProd = async (func: any) => {
env._set("NODE_ENV", nodeEnv) env._set("NODE_ENV", nodeEnv)
env._set("JEST_WORKER_ID", workerId) env._set("JEST_WORKER_ID", workerId)
} }
export function allowUndefined(expectation: jest.Expect) {
return expect.toBeOneOf([expectation, undefined, null])
}