Skip to content

Commit

Permalink
feat: add tests for processing hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
sidwebworks committed Jun 13, 2022
1 parent b827574 commit f7bb11b
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion tests/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "path"
import { assert, it } from "vitest"
import { assert, it, vitest } from "vitest"
import { readFile } from "xlsx"
import z from "zod"
import { createValidator } from "../src"
Expand Down Expand Up @@ -60,3 +60,31 @@ it("returns an array of valid items", async () => {
assert.isNotEmpty(result.valid)
assert.isEmpty(result.invalid)
})

it("calls the onValid hook when an item is valid", async () => {
const workbook = readFile(path.join(__dirname, "./mocks/demo.xls"))

const schema = z.object({
"First Name": z.string(),
"Last Name": z.string(),
Gender: z.enum(["Male", "Female"]),
Country: z.string(),
Age: z.number(),
Date: z.string(),
Id: z.number(),
})

const spy = vitest.spyOn(console, "log")

const validator = createValidator(workbook, {
onValid: () => {
console.log("VALID")
},
})

const result = await validator.validate(schema)

assert.strictEqual(spy.mock.calls.length, result.valid.length)

spy.mockClear()
})

0 comments on commit f7bb11b

Please sign in to comment.