Skip to content

Commit

Permalink
feat: add vitest setup and knock client constructor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
connorlindsey committed Jan 24, 2024
1 parent 2d4cc59 commit 2d6a3c1
Show file tree
Hide file tree
Showing 4 changed files with 734 additions and 1 deletion.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@
"lint": "tslint -p tsconfig.json -c tslint.json",
"prettier": "prettier \"src/**/*.{js,ts,tsx}\" --check",
"format": "prettier \"src/**/*.{js,ts,tsx}\" --write",
"test": "vitest",
"coverage": "vitest run --coverage",
"prepublishOnly": "npm run build"
},
"devDependencies": {
"@types/node": "^15.0.1",
"@types/pluralize": "0.0.29",
"prettier": "2.2.1",
"tslint": "6.1.3",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"vitest": "^1.2.1"
},
"dependencies": {
"jose": "^5.2.0"
Expand Down
24 changes: 24 additions & 0 deletions test/knock.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { describe, expect, test } from "vitest";
import { Knock } from "../src/knock";

describe("it can create a Knock client", () => {
test("it sets configuration values", () => {
const knock = new Knock("sk_test_12345", {
host: "http://test.knock.app",
});

expect(knock.key).toBe("sk_test_12345");
expect(knock.host).toBe("http://test.knock.app");
});

test("it defaults to reading the api key from env vars", () => {
process.env.KNOCK_API_KEY = "sk_test_12345";
const knock = new Knock();
expect(knock.key).toBe("sk_test_12345");
delete process.env.KNOCK_API_KEY;
});

test("it throws an error if no api key is provided", () => {
expect(() => new Knock(undefined)).toThrowError();
});
});
6 changes: 6 additions & 0 deletions vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from "vitest/config";

// Docs: https://vitest.dev/config/
export default defineConfig({
test: {},
});
Loading

0 comments on commit 2d6a3c1

Please sign in to comment.