Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Etoit/strict ts channels #22365

Merged
merged 2 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions code/lib/channels/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('Channel', () => {
const eventName = 'event1';

channel.addListener(eventName, jest.fn());
expect(channel.listeners(eventName).length).toBe(1);
expect(channel.listeners(eventName)?.length).toBe(1);
});
});

Expand All @@ -53,7 +53,7 @@ describe('Channel', () => {
const eventName = 'event1';

channel.on(eventName, jest.fn());
expect(channel.listeners(eventName).length).toBe(1);
expect(channel.listeners(eventName)?.length).toBe(1);
});
});

Expand All @@ -63,17 +63,17 @@ describe('Channel', () => {
const fn = jest.fn();

channel.on(eventName, fn);
expect(channel.listeners(eventName).length).toBe(1);
expect(channel.listeners(eventName)?.length).toBe(1);
channel.off(eventName, fn);
expect(channel.listeners(eventName).length).toBe(0);
expect(channel.listeners(eventName)?.length).toBe(0);
});
});

describe('method:emit', () => {
it('should execute the callback fn of a listener', () => {
const eventName = 'event1';
const listenerInputData = ['string1', 'string2', 'string3'];
let listenerOutputData: string[] = null;
let listenerOutputData: string[] | null = null;
const mockListener: Listener = (data) => {
listenerOutputData = data;
};
Expand All @@ -86,7 +86,7 @@ describe('Channel', () => {
it('should be callable with a spread operator as event arguments', () => {
const eventName = 'event1';
const listenerInputData = ['string1', 'string2', 'string3'];
let listenerOutputData: string[] = null;
let listenerOutputData: string[] | null = null;

channel.addListener(eventName, (...data) => {
listenerOutputData = data;
Expand Down Expand Up @@ -211,7 +211,7 @@ describe('Channel', () => {
const listenerToBeRemoved = jest.fn();
const listeners = [jest.fn(), jest.fn()];
const findListener = (listener: Listener) =>
channel.listeners(eventName).find((_listener) => _listener === listener);
channel.listeners(eventName)?.find((_listener) => _listener === listener);

listeners.forEach((fn) => channel.addListener(eventName, fn));
channel.addListener(eventName, listenerToBeRemoved);
Expand Down
2 changes: 1 addition & 1 deletion code/lib/channels/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"extends": "../../tsconfig.json",
"include": ["src/**/*"],
"compilerOptions": {
"strict": false
"strict": true
}
}