refactor: monorepo+pnpm (removed husky)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { getEditorLangForMimeType } from "../editorutils"
|
||||
|
||||
describe("getEditorLangForMimeType", () => {
|
||||
test("returns 'json' for valid JSON mimes", () => {
|
||||
expect(getEditorLangForMimeType("application/json")).toMatch("json")
|
||||
expect(getEditorLangForMimeType("application/hal+json")).toMatch("json")
|
||||
expect(getEditorLangForMimeType("application/vnd.api+json")).toMatch("json")
|
||||
})
|
||||
|
||||
test("returns 'xml' for valid XML mimes", () => {
|
||||
expect(getEditorLangForMimeType("application/xml")).toMatch("xml")
|
||||
})
|
||||
|
||||
test("returns 'html' for valid HTML mimes", () => {
|
||||
expect(getEditorLangForMimeType("text/html")).toMatch("html")
|
||||
})
|
||||
|
||||
test("returns 'plain_text' for plain text mime", () => {
|
||||
expect(getEditorLangForMimeType("text/plain")).toMatch("plain_text")
|
||||
})
|
||||
|
||||
test("returns 'plain_text' for unimplemented mimes", () => {
|
||||
expect(getEditorLangForMimeType("image/gif")).toMatch("plain_text")
|
||||
})
|
||||
|
||||
test("returns 'plain_text' for null/undefined mimes", () => {
|
||||
expect(getEditorLangForMimeType(null)).toMatch("plain_text")
|
||||
expect(getEditorLangForMimeType(undefined)).toMatch("plain_text")
|
||||
})
|
||||
})
|
||||
34
packages/hoppscotch-app/helpers/__tests__/jsonParse.spec.js
Normal file
34
packages/hoppscotch-app/helpers/__tests__/jsonParse.spec.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import jsonParse from "../jsonParse"
|
||||
|
||||
describe("jsonParse", () => {
|
||||
test("parses without errors for valid JSON", () => {
|
||||
const testJSON = JSON.stringify({
|
||||
name: "hoppscotch",
|
||||
url: "https://hoppscotch.io",
|
||||
awesome: true,
|
||||
when: 2019,
|
||||
})
|
||||
|
||||
expect(() => jsonParse(testJSON)).not.toThrow()
|
||||
})
|
||||
|
||||
test("throws error for invalid JSON", () => {
|
||||
const testJSON = '{ "name": hopp "url": true }'
|
||||
|
||||
expect(() => jsonParse(testJSON)).toThrow()
|
||||
})
|
||||
|
||||
test("thrown error has proper info fields", () => {
|
||||
expect.assertions(3)
|
||||
|
||||
const testJSON = '{ "name": hopp "url": true }'
|
||||
|
||||
try {
|
||||
jsonParse(testJSON)
|
||||
} catch (e) {
|
||||
expect(e).toHaveProperty("start")
|
||||
expect(e).toHaveProperty("end")
|
||||
expect(e).toHaveProperty("message")
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,84 @@
|
||||
import { cancelRunningRequest, sendNetworkRequest } from "../network"
|
||||
|
||||
import AxiosStrategy, {
|
||||
cancelRunningAxiosRequest,
|
||||
} from "../strategies/AxiosStrategy"
|
||||
import ExtensionStrategy, {
|
||||
cancelRunningExtensionRequest,
|
||||
hasExtensionInstalled,
|
||||
} from "../strategies/ExtensionStrategy"
|
||||
|
||||
jest.mock("../strategies/AxiosStrategy", () => ({
|
||||
__esModule: true,
|
||||
default: jest.fn(() => Promise.resolve()),
|
||||
cancelRunningAxiosRequest: jest.fn(() => Promise.resolve()),
|
||||
}))
|
||||
|
||||
jest.mock("../strategies/ExtensionStrategy", () => ({
|
||||
__esModule: true,
|
||||
default: jest.fn(() => Promise.resolve()),
|
||||
cancelRunningExtensionRequest: jest.fn(() => Promise.resolve()),
|
||||
hasExtensionInstalled: jest.fn(),
|
||||
}))
|
||||
|
||||
jest.mock("~/newstore/settings", () => {
|
||||
return {
|
||||
settingsStore: {
|
||||
value: {
|
||||
EXTENSIONS_ENABLED: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
global.$nuxt = {
|
||||
$loading: {
|
||||
finish: jest.fn(() => Promise.resolve()),
|
||||
},
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks() // Reset the call count for the mock functions
|
||||
})
|
||||
|
||||
describe("cancelRunningRequest", () => {
|
||||
test("cancels only axios request if extension not allowed in settings and extension is installed", () => {
|
||||
hasExtensionInstalled.mockReturnValue(true)
|
||||
|
||||
cancelRunningRequest()
|
||||
|
||||
expect(cancelRunningExtensionRequest).not.toHaveBeenCalled()
|
||||
expect(cancelRunningAxiosRequest).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
test("cancels only axios request if extension is not allowed and not installed", () => {
|
||||
hasExtensionInstalled.mockReturnValue(false)
|
||||
|
||||
cancelRunningRequest()
|
||||
|
||||
expect(cancelRunningExtensionRequest).not.toHaveBeenCalled()
|
||||
expect(cancelRunningAxiosRequest).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe("sendNetworkRequest", () => {
|
||||
test("runs only axios request if extension not allowed in settings and extension is installed and clears the progress bar", async () => {
|
||||
hasExtensionInstalled.mockReturnValue(true)
|
||||
|
||||
await sendNetworkRequest({})
|
||||
|
||||
expect(ExtensionStrategy).not.toHaveBeenCalled()
|
||||
expect(AxiosStrategy).toHaveBeenCalled()
|
||||
expect(global.$nuxt.$loading.finish).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
test("runs only axios request if extension is not allowed and not installed and clears the progress bar", async () => {
|
||||
hasExtensionInstalled.mockReturnValue(false)
|
||||
|
||||
await sendNetworkRequest({})
|
||||
|
||||
expect(ExtensionStrategy).not.toHaveBeenCalled()
|
||||
expect(AxiosStrategy).toHaveBeenCalled()
|
||||
expect(global.$nuxt.$loading.finish).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,83 @@
|
||||
import { cancelRunningRequest, sendNetworkRequest } from "../network"
|
||||
|
||||
import AxiosStrategy, {
|
||||
cancelRunningAxiosRequest,
|
||||
} from "../strategies/AxiosStrategy"
|
||||
import ExtensionStrategy, {
|
||||
cancelRunningExtensionRequest,
|
||||
hasExtensionInstalled,
|
||||
} from "../strategies/ExtensionStrategy"
|
||||
|
||||
jest.mock("../strategies/AxiosStrategy", () => ({
|
||||
__esModule: true,
|
||||
default: jest.fn(() => Promise.resolve()),
|
||||
cancelRunningAxiosRequest: jest.fn(() => Promise.resolve()),
|
||||
}))
|
||||
|
||||
jest.mock("../strategies/ExtensionStrategy", () => ({
|
||||
__esModule: true,
|
||||
default: jest.fn(() => Promise.resolve()),
|
||||
cancelRunningExtensionRequest: jest.fn(() => Promise.resolve()),
|
||||
hasExtensionInstalled: jest.fn(),
|
||||
}))
|
||||
|
||||
jest.mock("~/newstore/settings", () => {
|
||||
return {
|
||||
settingsStore: {
|
||||
value: {
|
||||
EXTENSIONS_ENABLED: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
global.$nuxt = {
|
||||
$loading: {
|
||||
finish: jest.fn(() => Promise.resolve()),
|
||||
},
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks() // Reset the call count for the mock functions
|
||||
})
|
||||
|
||||
describe("cancelRunningRequest", () => {
|
||||
test("cancels only extension request if extension allowed in settings and is installed", () => {
|
||||
hasExtensionInstalled.mockReturnValue(true)
|
||||
|
||||
cancelRunningRequest()
|
||||
|
||||
expect(cancelRunningAxiosRequest).not.toHaveBeenCalled()
|
||||
expect(cancelRunningExtensionRequest).toHaveBeenCalled()
|
||||
})
|
||||
test("cancels only axios request if extension is allowed but not installed", () => {
|
||||
hasExtensionInstalled.mockReturnValue(false)
|
||||
|
||||
cancelRunningRequest()
|
||||
|
||||
expect(cancelRunningExtensionRequest).not.toHaveBeenCalled()
|
||||
expect(cancelRunningAxiosRequest).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe("sendNetworkRequest", () => {
|
||||
test("runs only extension request if extension allowed in settings and is installed and clears the progress bar", async () => {
|
||||
hasExtensionInstalled.mockReturnValue(true)
|
||||
|
||||
await sendNetworkRequest({})
|
||||
|
||||
expect(AxiosStrategy).not.toHaveBeenCalled()
|
||||
expect(ExtensionStrategy).toHaveBeenCalled()
|
||||
expect(global.$nuxt.$loading.finish).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
test("runs only axios request if extension is allowed but not installed and clears the progress bar", async () => {
|
||||
hasExtensionInstalled.mockReturnValue(false)
|
||||
|
||||
await sendNetworkRequest({})
|
||||
|
||||
expect(ExtensionStrategy).not.toHaveBeenCalled()
|
||||
expect(AxiosStrategy).toHaveBeenCalled()
|
||||
expect(global.$nuxt.$loading.finish).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,42 @@
|
||||
import { getPlatformSpecialKey } from "../platformutils"
|
||||
|
||||
describe("getPlatformSpecialKey", () => {
|
||||
let platformGetter
|
||||
|
||||
beforeEach(() => {
|
||||
platformGetter = jest.spyOn(navigator, "platform", "get")
|
||||
})
|
||||
|
||||
test("returns '⌘' for Apple platforms", () => {
|
||||
platformGetter.mockReturnValue("Mac")
|
||||
expect(getPlatformSpecialKey()).toMatch("⌘")
|
||||
|
||||
platformGetter.mockReturnValue("iPhone")
|
||||
expect(getPlatformSpecialKey()).toMatch("⌘")
|
||||
|
||||
platformGetter.mockReturnValue("iPad")
|
||||
expect(getPlatformSpecialKey()).toMatch("⌘")
|
||||
|
||||
platformGetter.mockReturnValue("iPod")
|
||||
expect(getPlatformSpecialKey()).toMatch("⌘")
|
||||
})
|
||||
|
||||
test("return 'Ctrl' for non-Apple platforms", () => {
|
||||
platformGetter.mockReturnValue("Android")
|
||||
expect(getPlatformSpecialKey()).toMatch("Ctrl")
|
||||
|
||||
platformGetter.mockReturnValue("Windows")
|
||||
expect(getPlatformSpecialKey()).toMatch("Ctrl")
|
||||
|
||||
platformGetter.mockReturnValue("Linux")
|
||||
expect(getPlatformSpecialKey()).toMatch("Ctrl")
|
||||
})
|
||||
|
||||
test("returns 'Ctrl' for null/undefined platforms", () => {
|
||||
platformGetter.mockReturnValue(null)
|
||||
expect(getPlatformSpecialKey()).toMatch("Ctrl")
|
||||
|
||||
platformGetter.mockReturnValue(undefined)
|
||||
expect(getPlatformSpecialKey()).toMatch("Ctrl")
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,313 @@
|
||||
import runTestScriptWithVariables from "../postwomanTesting"
|
||||
|
||||
/**
|
||||
* @param {string} script
|
||||
* @param {number} index
|
||||
*/
|
||||
function getTestResult(script, index) {
|
||||
return runTestScriptWithVariables(script).testResults[index].result
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} script
|
||||
*/
|
||||
function getErrors(script) {
|
||||
return runTestScriptWithVariables(script).errors
|
||||
}
|
||||
|
||||
describe("Error handling", () => {
|
||||
test("throws error at unknown test method", () => {
|
||||
const testScriptWithUnknownMethod = "pw.expect(1).toBeSomeUnknownMethod()"
|
||||
expect(() => {
|
||||
runTestScriptWithVariables(testScriptWithUnknownMethod)
|
||||
}).toThrow()
|
||||
})
|
||||
test("errors array is empty on a successful test", () => {
|
||||
expect(getErrors("pw.expect(1).toBe(1)")).toStrictEqual([])
|
||||
})
|
||||
test("throws error at a variable which is not declared", () => {
|
||||
expect(() => {
|
||||
runTestScriptWithVariables("someVariable")
|
||||
}).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe("toBe", () => {
|
||||
test("test for numbers", () => {
|
||||
expect(getTestResult("pw.expect(1).toBe(2)", 0)).toEqual("FAIL")
|
||||
|
||||
expect(getTestResult("pw.expect(1).toBe(1)", 0)).toEqual("PASS")
|
||||
})
|
||||
|
||||
test("test for strings", () => {
|
||||
expect(getTestResult("pw.expect('hello').toBe('bonjour')", 0)).toEqual(
|
||||
"FAIL"
|
||||
)
|
||||
expect(getTestResult("pw.expect('hi').toBe('hi')", 0)).toEqual("PASS")
|
||||
})
|
||||
|
||||
test("test for negative assertion (.not.toBe)", () => {
|
||||
expect(getTestResult("pw.expect(1).not.toBe(1)", 0)).toEqual("FAIL")
|
||||
expect(getTestResult("pw.expect(1).not.toBe(2)", 0)).toEqual("PASS")
|
||||
expect(getTestResult("pw.expect('world').not.toBe('planet')", 0)).toEqual(
|
||||
"PASS"
|
||||
)
|
||||
expect(getTestResult("pw.expect('world').not.toBe('world')", 0)).toEqual(
|
||||
"FAIL"
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("toHaveProperty", () => {
|
||||
const dummyResponse = {
|
||||
id: 843,
|
||||
description: "random",
|
||||
}
|
||||
|
||||
test("test for positive assertion (.toHaveProperty)", () => {
|
||||
expect(
|
||||
getTestResult(
|
||||
`pw.expect(${JSON.stringify(dummyResponse)}).toHaveProperty("id")`,
|
||||
0
|
||||
)
|
||||
).toEqual("PASS")
|
||||
expect(
|
||||
getTestResult(`pw.expect(${dummyResponse.id}).toBe(843)`, 0)
|
||||
).toEqual("PASS")
|
||||
})
|
||||
test("test for negative assertion (.not.toHaveProperty)", () => {
|
||||
expect(
|
||||
getTestResult(
|
||||
`pw.expect(${JSON.stringify(
|
||||
dummyResponse
|
||||
)}).not.toHaveProperty("type")`,
|
||||
0
|
||||
)
|
||||
).toEqual("PASS")
|
||||
expect(
|
||||
getTestResult(
|
||||
`pw.expect(${JSON.stringify(dummyResponse)}).toHaveProperty("type")`,
|
||||
0
|
||||
)
|
||||
).toEqual("FAIL")
|
||||
})
|
||||
})
|
||||
|
||||
describe("toBeLevel2xx", () => {
|
||||
test("test for numbers", () => {
|
||||
expect(getTestResult("pw.expect(200).toBeLevel2xx()", 0)).toEqual("PASS")
|
||||
expect(getTestResult("pw.expect(200).not.toBeLevel2xx()", 0)).toEqual(
|
||||
"FAIL"
|
||||
)
|
||||
expect(getTestResult("pw.expect(300).toBeLevel2xx()", 0)).toEqual("FAIL")
|
||||
expect(getTestResult("pw.expect(300).not.toBeLevel2xx()", 0)).toEqual(
|
||||
"PASS"
|
||||
)
|
||||
})
|
||||
test("test for strings", () => {
|
||||
expect(getTestResult("pw.expect('200').toBeLevel2xx()", 0)).toEqual("PASS")
|
||||
expect(getTestResult("pw.expect('200').not.toBeLevel2xx()", 0)).toEqual(
|
||||
"FAIL"
|
||||
)
|
||||
expect(getTestResult("pw.expect('300').toBeLevel2xx()", 0)).toEqual("FAIL")
|
||||
expect(getTestResult("pw.expect('300').not.toBeLevel2xx()", 0)).toEqual(
|
||||
"PASS"
|
||||
)
|
||||
})
|
||||
test("failed to parse to integer", () => {
|
||||
expect(getTestResult("pw.expect(undefined).toBeLevel2xx()", 0)).toEqual(
|
||||
"FAIL"
|
||||
)
|
||||
expect(getTestResult("pw.expect(null).toBeLevel2xx()", 0)).toEqual("FAIL")
|
||||
expect(() => {
|
||||
runTestScriptWithVariables("pw.expect(Symbol('test')).toBeLevel2xx()")
|
||||
}).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe("toBeLevel3xx()", () => {
|
||||
test("test for numbers", () => {
|
||||
expect(getTestResult("pw.expect(300).toBeLevel3xx()", 0)).toEqual("PASS")
|
||||
expect(getTestResult("pw.expect(300).not.toBeLevel3xx()", 0)).toEqual(
|
||||
"FAIL"
|
||||
)
|
||||
expect(getTestResult("pw.expect(400).toBeLevel3xx()", 0)).toEqual("FAIL")
|
||||
expect(getTestResult("pw.expect(400).not.toBeLevel3xx()", 0)).toEqual(
|
||||
"PASS"
|
||||
)
|
||||
})
|
||||
test("test for strings", () => {
|
||||
expect(getTestResult("pw.expect('300').toBeLevel3xx()", 0)).toEqual("PASS")
|
||||
expect(getTestResult("pw.expect('300').not.toBeLevel3xx()", 0)).toEqual(
|
||||
"FAIL"
|
||||
)
|
||||
expect(getTestResult("pw.expect('400').toBeLevel3xx()", 0)).toEqual("FAIL")
|
||||
expect(getTestResult("pw.expect('400').not.toBeLevel3xx()", 0)).toEqual(
|
||||
"PASS"
|
||||
)
|
||||
})
|
||||
test("failed to parse to integer", () => {
|
||||
expect(getTestResult("pw.expect(undefined).toBeLevel3xx()", 0)).toEqual(
|
||||
"FAIL"
|
||||
)
|
||||
expect(getTestResult("pw.expect(null).toBeLevel3xx()", 0)).toEqual("FAIL")
|
||||
expect(() => {
|
||||
runTestScriptWithVariables("pw.expect(Symbol('test')).toBeLevel3xx()")
|
||||
}).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe("toBeLevel4xx()", () => {
|
||||
test("test for numbers", () => {
|
||||
expect(getTestResult("pw.expect(400).toBeLevel4xx()", 0)).toEqual("PASS")
|
||||
expect(getTestResult("pw.expect(400).not.toBeLevel4xx()", 0)).toEqual(
|
||||
"FAIL"
|
||||
)
|
||||
expect(getTestResult("pw.expect(500).toBeLevel4xx()", 0)).toEqual("FAIL")
|
||||
expect(getTestResult("pw.expect(500).not.toBeLevel4xx()", 0)).toEqual(
|
||||
"PASS"
|
||||
)
|
||||
})
|
||||
test("test for strings", () => {
|
||||
expect(getTestResult("pw.expect('400').toBeLevel4xx()", 0)).toEqual("PASS")
|
||||
expect(getTestResult("pw.expect('400').not.toBeLevel4xx()", 0)).toEqual(
|
||||
"FAIL"
|
||||
)
|
||||
expect(getTestResult("pw.expect('500').toBeLevel4xx()", 0)).toEqual("FAIL")
|
||||
expect(getTestResult("pw.expect('500').not.toBeLevel4xx()", 0)).toEqual(
|
||||
"PASS"
|
||||
)
|
||||
})
|
||||
test("failed to parse to integer", () => {
|
||||
expect(getTestResult("pw.expect(undefined).toBeLevel4xx()", 0)).toEqual(
|
||||
"FAIL"
|
||||
)
|
||||
expect(getTestResult("pw.expect(null).toBeLevel4xx()", 0)).toEqual("FAIL")
|
||||
expect(() => {
|
||||
runTestScriptWithVariables("pw.expect(Symbol('test')).toBeLevel4xx()")
|
||||
}).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe("toBeLevel5xx()", () => {
|
||||
test("test for numbers", () => {
|
||||
expect(getTestResult("pw.expect(500).toBeLevel5xx()", 0)).toEqual("PASS")
|
||||
expect(getTestResult("pw.expect(500).not.toBeLevel5xx()", 0)).toEqual(
|
||||
"FAIL"
|
||||
)
|
||||
expect(getTestResult("pw.expect(200).toBeLevel5xx()", 0)).toEqual("FAIL")
|
||||
expect(getTestResult("pw.expect(200).not.toBeLevel5xx()", 0)).toEqual(
|
||||
"PASS"
|
||||
)
|
||||
})
|
||||
test("test for strings", () => {
|
||||
expect(getTestResult("pw.expect('500').toBeLevel5xx()", 0)).toEqual("PASS")
|
||||
expect(getTestResult("pw.expect('500').not.toBeLevel5xx()", 0)).toEqual(
|
||||
"FAIL"
|
||||
)
|
||||
expect(getTestResult("pw.expect('200').toBeLevel5xx()", 0)).toEqual("FAIL")
|
||||
expect(getTestResult("pw.expect('200').not.toBeLevel5xx()", 0)).toEqual(
|
||||
"PASS"
|
||||
)
|
||||
})
|
||||
test("failed to parse to integer", () => {
|
||||
expect(getTestResult("pw.expect(undefined).toBeLevel5xx()", 0)).toEqual(
|
||||
"FAIL"
|
||||
)
|
||||
expect(getTestResult("pw.expect(null).toBeLevel5xx()", 0)).toEqual("FAIL")
|
||||
expect(() => {
|
||||
runTestScriptWithVariables("pw.expect(Symbol('test')).toBeLevel5xx()")
|
||||
}).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe("toHaveLength()", () => {
|
||||
test("test for strings", () => {
|
||||
expect(getTestResult("pw.expect('word').toHaveLength(4)", 0)).toEqual(
|
||||
"PASS"
|
||||
)
|
||||
expect(getTestResult("pw.expect('word').toHaveLength(5)", 0)).toEqual(
|
||||
"FAIL"
|
||||
)
|
||||
expect(getTestResult("pw.expect('word').not.toHaveLength(4)", 0)).toEqual(
|
||||
"FAIL"
|
||||
)
|
||||
expect(getTestResult("pw.expect('word').not.toHaveLength(5)", 0)).toEqual(
|
||||
"PASS"
|
||||
)
|
||||
})
|
||||
test("test for arrays", () => {
|
||||
const fruits =
|
||||
"['apples', 'bananas', 'oranges', 'grapes', 'strawberries', 'cherries']"
|
||||
expect(getTestResult(`pw.expect(${fruits}).toHaveLength(6)`, 0)).toEqual(
|
||||
"PASS"
|
||||
)
|
||||
expect(getTestResult(`pw.expect(${fruits}).toHaveLength(7)`, 0)).toEqual(
|
||||
"FAIL"
|
||||
)
|
||||
expect(
|
||||
getTestResult(`pw.expect(${fruits}).not.toHaveLength(6)`, 0)
|
||||
).toEqual("FAIL")
|
||||
expect(
|
||||
getTestResult(`pw.expect(${fruits}).not.toHaveLength(7)`, 0)
|
||||
).toEqual("PASS")
|
||||
})
|
||||
})
|
||||
|
||||
describe("toBeType()", () => {
|
||||
test("test for positive assertion", () => {
|
||||
expect(getTestResult("pw.expect('random').toBeType('string')", 0)).toEqual(
|
||||
"PASS"
|
||||
)
|
||||
expect(getTestResult("pw.expect(true).toBeType('boolean')", 0)).toEqual(
|
||||
"PASS"
|
||||
)
|
||||
expect(getTestResult("pw.expect(5).toBeType('number')", 0)).toEqual("PASS")
|
||||
expect(
|
||||
getTestResult("pw.expect(new Date()).toBeType('object')", 0)
|
||||
).toEqual("PASS")
|
||||
expect(
|
||||
getTestResult("pw.expect(undefined).toBeType('undefined')", 0)
|
||||
).toEqual("PASS")
|
||||
expect(
|
||||
getTestResult("pw.expect(BigInt(123)).toBeType('bigint')", 0)
|
||||
).toEqual("PASS")
|
||||
expect(
|
||||
getTestResult("pw.expect(Symbol('test')).toBeType('symbol')", 0)
|
||||
).toEqual("PASS")
|
||||
expect(
|
||||
getTestResult("pw.expect(function() {}).toBeType('function')", 0)
|
||||
).toEqual("PASS")
|
||||
})
|
||||
test("test for negative assertion", () => {
|
||||
expect(
|
||||
getTestResult("pw.expect('random').not.toBeType('string')", 0)
|
||||
).toEqual("FAIL")
|
||||
expect(getTestResult("pw.expect(true).not.toBeType('boolean')", 0)).toEqual(
|
||||
"FAIL"
|
||||
)
|
||||
expect(getTestResult("pw.expect(5).not.toBeType('number')", 0)).toEqual(
|
||||
"FAIL"
|
||||
)
|
||||
expect(
|
||||
getTestResult("pw.expect(new Date()).not.toBeType('object')", 0)
|
||||
).toEqual("FAIL")
|
||||
expect(
|
||||
getTestResult("pw.expect(undefined).not.toBeType('undefined')", 0)
|
||||
).toEqual("FAIL")
|
||||
expect(
|
||||
getTestResult("pw.expect(BigInt(123)).not.toBeType('bigint')", 0)
|
||||
).toEqual("FAIL")
|
||||
expect(
|
||||
getTestResult("pw.expect(Symbol('test')).not.toBeType('symbol')", 0)
|
||||
).toEqual("FAIL")
|
||||
expect(
|
||||
getTestResult("pw.expect(function() {}).not.toBeType('function')", 0)
|
||||
).toEqual("FAIL")
|
||||
})
|
||||
test("unexpected type", () => {
|
||||
expect(getTestResult("pw.expect('random').toBeType('unknown')", 0)).toEqual(
|
||||
"FAIL"
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user