Skip to content

Commit d8052a2

Browse files
committed
chore: event listener tests
1 parent 2040b94 commit d8052a2

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

src/pipeline/pipeline.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class Pipeline<T, P = unknown> extends EventEmitter<PipelineEvents<T>> {
7373
processor: PipelineProcessor<any, any>,
7474
priority: number = null,
7575
): void {
76+
if (!processor) return;
77+
7678
if (processor.type === null) {
7779
throw Error('Processor type is not defined');
7880
}

src/view/plugin/search/search.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function Search() {
6767
}, [props]);
6868

6969
useEffect(() => {
70-
if (processor) config.pipeline.register(processor);
70+
config.pipeline.register(processor);
7171

7272
return () => config.pipeline.unregister(processor);
7373
}, [config, processor]);

src/view/plugin/sort/sort.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function Sort(
5353
}, []);
5454

5555
useEffect(() => {
56-
if (processor) config.pipeline.register(processor);
56+
config.pipeline.register(processor);
5757

5858
return () => config.pipeline.unregister(processor);
5959
}, [config, processor]);

tests/jest/view/container.test.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ import {
88
ProcessorType,
99
} from '../../../src/pipeline/processor';
1010
import { flushPromises } from '../testUtil';
11-
import { EventEmitter } from '../../../src/util/eventEmitter';
12-
import { GridEvents } from '../../../src/events';
13-
import { PluginManager } from '../../../src/plugin';
1411
import { Status } from '../../../src/types';
1512
import * as TableActions from '../../../src/view/actions';
1613
import Tabular from '../../../src/tabular';
@@ -21,14 +18,16 @@ describe('Container component', () => {
2118
let config: Config;
2219

2320
beforeEach(() => {
24-
config = Config.fromPartialConfig({
21+
config = new Config().update({
2522
data: [
2623
[1, 2, 3],
2724
['a', 'b', 'c'],
2825
],
29-
}) as Config;
30-
config.eventEmitter = new EventEmitter<GridEvents>();
31-
config.plugin = new PluginManager();
26+
});
27+
});
28+
29+
afterEach(() => {
30+
jest.clearAllMocks();
3231
});
3332

3433
it('should render a container with table', async () => {
@@ -338,7 +337,7 @@ describe('Container component', () => {
338337
});
339338

340339
it('should unregister the processors', async () => {
341-
const config = Config.fromPartialConfig({
340+
const config = new Config().update({
342341
pagination: true,
343342
search: true,
344343
sort: true,
@@ -375,6 +374,9 @@ describe('Container component', () => {
375374

376375
container.unmount();
377376

377+
await flushPromises();
378+
await flushPromises();
379+
await flushPromises();
378380
await flushPromises();
379381

380382
expect(mockUnregister.mock.calls.length).toBe(

0 commit comments

Comments
 (0)