-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest.ts
69 lines (64 loc) · 2.14 KB
/
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
57
58
59
60
61
62
63
64
65
66
67
68
69
import { Base } from "./src";
const fooPlugin = (test: Base) => {
return {
foo: () => "foo",
};
};
const barPlugin = (test: Base) => {
return {
bar: () => "bar",
};
};
const pluginWithEmptyObjectReturn = (test: Base) => {
return {};
};
describe("Base", () => {
it(".plugin(fooPlugin)", () => {
const FooTest = Base.plugin(fooPlugin);
const fooTest = new FooTest();
expect(fooTest.foo()).toEqual("foo");
});
it(".plugin(fooPlugin, barPlugin)", () => {
const FooBarTest = Base.plugin(fooPlugin, barPlugin);
const fooBarTest = new FooBarTest();
expect(fooBarTest.foo()).toEqual("foo");
expect(fooBarTest.bar()).toEqual("bar");
});
it(".plugin(fooPlugin, barPlugin, pluginWithVoidReturn)", () => {
const FooBarTest = Base.plugin(
fooPlugin,
barPlugin,
pluginWithEmptyObjectReturn
);
const fooBarTest = new FooBarTest();
expect(fooBarTest.foo()).toEqual("foo");
expect(fooBarTest.bar()).toEqual("bar");
});
it(".plugin(fooPlugin).plugin(barPlugin)", () => {
const FooBarTest = Base.plugin(fooPlugin).plugin(barPlugin);
const fooBarTest = new FooBarTest();
expect(fooBarTest.foo()).toEqual("foo");
expect(fooBarTest.bar()).toEqual("bar");
});
it(".defaults({foo: 'bar'})", () => {
const BaseWithDefaults = Base.defaults({ foo: "bar" });
const defaultsTest = new BaseWithDefaults();
const mergedOptionsTest = new BaseWithDefaults({ baz: "daz" });
expect(defaultsTest.options).toStrictEqual({ foo: "bar" });
expect(mergedOptionsTest.options).toStrictEqual({ foo: "bar", baz: "daz" });
});
it(".plugin().defaults()", () => {
const BaseWithPluginAndDefaults = Base.plugin(fooPlugin).defaults({
baz: "daz",
});
const BaseWithDefaultsAndPlugin = Base.defaults({
baz: "daz",
}).plugin(fooPlugin);
const instance1 = new BaseWithPluginAndDefaults();
const instance2 = new BaseWithDefaultsAndPlugin();
expect(instance1.foo()).toEqual("foo");
expect(instance1.options).toStrictEqual({ baz: "daz" });
expect(instance2.foo()).toEqual("foo");
expect(instance2.options).toStrictEqual({ baz: "daz" });
});
});