-
Notifications
You must be signed in to change notification settings - Fork 2
/
basic_setup_tests.test.ts
56 lines (49 loc) · 1.42 KB
/
basic_setup_tests.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2023-2023 the Nifty li'l' tricks authors. All rights reserved. MIT license.
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
import {
afterEach,
beforeEach,
describe,
it,
} from "https://deno.land/std/testing/bdd.ts";
import {
setupTestsFactory,
SetupTestsTeardown,
} from "https://deno.land/x/nifty_lil_tricks_testing/mod.ts";
// Define or import a plugin as follows:
const helloWorldPlugin = {
setup: (config: { message: string }) => {
// Setup plugin according to config
return {
output: config,
teardown: () => {},
};
},
};
// In another file, load plugins as follows to generate a setupTests function:
export const { setupTests } = setupTestsFactory({
helloWorld: helloWorldPlugin,
});
// Then one can use this in any test file as follows:
describe("Service", () => {
let teardownTests: SetupTestsTeardown;
let message: string;
beforeEach(async () => {
// Setup tests
const result = await setupTests({
helloWorld: { message: "Hello, world!" },
});
message = result.outputs.helloWorld.output.message;
teardownTests = result.teardownTests;
});
afterEach(async () => {
// Teardown tests
await teardownTests();
});
describe("method", () => {
it("should test something that relies on the plugin being configured", () => {
// Some other testing
assertEquals(message, "Hello, world!");
});
});
});