UNPKG

2.31 kBJavaScriptView Raw
1import PluginHandler from '../src/PluginHandler'
2
3
4describe('PluginHandler', () => {
5
6
7 it('add plugin', function () {
8
9 const pluginHandler = new PluginHandler();
10
11 pluginHandler.addPlugin({
12 namespace: 'loading'
13 }, {
14 namespace: 'undo'
15 })
16
17 const hasLoadingPlugin = pluginHandler.plugins.some(({namespace}) => namespace === 'loading'),
18 hasUndoPlugin = pluginHandler.plugins.some(({namespace}) => namespace === 'undo');
19
20
21 expect(hasLoadingPlugin).toEqual(true)
22
23 expect(hasUndoPlugin).toEqual(true)
24
25 });
26
27 it('add repeated plugin', function () {
28
29 const pluginHandler = new PluginHandler();
30
31 function addPluginFun() {
32 pluginHandler.addPlugin({
33 namespace: 'loading'
34 }, {
35 namespace: 'loading'
36 })
37 }
38
39 expect(addPluginFun).toThrow(`[dura.core.plugin] namespace should be unique , the repeated namespace is loading`)
40
41 });
42
43 it('getOnReducerEventFun', function () {
44
45 const pluginHandler = new PluginHandler();
46
47 pluginHandler.addPlugin({
48 namespace: 'loadingPlugin',
49 onReducer: function (reducer) {
50 return function (state, action) {
51 reducer(state, action)
52 }
53 }
54 }, {
55 namespace: 'undoPlugin',
56 onReducer: function (reducer) {
57 return function (state, action) {
58 reducer(state, action)
59 }
60 }
61 })
62
63 expect(pluginHandler.getOnReducerEventFun().length).toEqual(2)
64
65 });
66
67 it('getOnEffectEventFun', function () {
68
69 const pluginHandler = new PluginHandler();
70
71 pluginHandler.addPlugin({
72 namespace: 'loadingPlugin',
73 onEffect: function (effect) {
74 return function* (args) {
75 yield effect(args)
76 }
77 }
78 },{
79 namespace: 'undoPlugin',
80 onReducer: function (reducer) {
81 return function (state, action) {
82 reducer(state, action)
83 }
84 }
85 })
86
87 expect(pluginHandler.getOnEffectEventFun().length).toEqual(1)
88
89 });
90
91})
\No newline at end of file