refactor: move hoppscotch-common tests to vitest (#3154)
This commit is contained in:
@@ -1,14 +1,11 @@
|
||||
import { TextDecoder } from "util"
|
||||
import { describe, expect, test } from "vitest"
|
||||
import { decodeB64StringToArrayBuffer } from "../b64"
|
||||
|
||||
describe("decodeB64StringToArrayBuffer", () => {
|
||||
test("decodes content correctly", () => {
|
||||
const decoder = new TextDecoder("utf-8")
|
||||
expect(
|
||||
decoder.decode(
|
||||
decodeB64StringToArrayBuffer("aG9wcHNjb3RjaCBpcyBhd2Vzb21lIQ==")
|
||||
)
|
||||
).toMatch("hoppscotch is awesome!")
|
||||
decodeB64StringToArrayBuffer("aG9wcHNjb3RjaCBpcyBhd2Vzb21lIQ==")
|
||||
).toEqual(Buffer.from("hoppscotch is awesome!", "utf-8").buffer)
|
||||
})
|
||||
|
||||
// TODO : More tests for binary data ?
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { describe, expect, test } from "vitest"
|
||||
import { isJSONContentType } from "../contenttypes"
|
||||
|
||||
describe("isJSONContentType", () => {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { vi, describe, test, expect } from "vitest"
|
||||
import debounce from "../debounce"
|
||||
|
||||
describe("debounce", () => {
|
||||
test("doesn't call function right after calling", () => {
|
||||
const fn = jest.fn()
|
||||
const fn = vi.fn()
|
||||
|
||||
const debFunc = debounce(fn, 100)
|
||||
debFunc()
|
||||
@@ -11,27 +12,27 @@ describe("debounce", () => {
|
||||
})
|
||||
|
||||
test("calls the function after the given timeout", () => {
|
||||
const fn = jest.fn()
|
||||
const fn = vi.fn()
|
||||
|
||||
jest.useFakeTimers()
|
||||
vi.useFakeTimers()
|
||||
|
||||
const debFunc = debounce(fn, 100)
|
||||
debFunc()
|
||||
|
||||
jest.runAllTimers()
|
||||
vi.runAllTimers()
|
||||
|
||||
expect(fn).toHaveBeenCalled()
|
||||
// expect(setTimeout).toHaveBeenCalledWith(expect.any(Function), 100)
|
||||
})
|
||||
|
||||
test("calls the function only one time within the timeframe", () => {
|
||||
const fn = jest.fn()
|
||||
const fn = vi.fn()
|
||||
|
||||
const debFunc = debounce(fn, 1000)
|
||||
|
||||
for (let i = 0; i < 100; i++) debFunc()
|
||||
|
||||
jest.runAllTimers()
|
||||
vi.runAllTimers()
|
||||
|
||||
expect(fn).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { describe, expect, test } from "vitest"
|
||||
import { parseUrlAndPath } from "../uri"
|
||||
|
||||
describe("parseUrlAndPath", () => {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { describe, test, expect } from "vitest"
|
||||
import { wsValid, httpValid, socketioValid } from "../valid"
|
||||
|
||||
describe("wsValid", () => {
|
||||
|
||||
Reference in New Issue
Block a user