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

fix(emitter): off() ignoring handler check when one listener remains #1099

Merged
merged 1 commit into from
Jul 6, 2023

Conversation

tassoevan
Copy link
Collaborator

Proposed changes (including videos or screenshots)

For any Emitter instance, if there is only one event handler attached to some event x, calling emitter.off('x', handler) will wipe that handler regardless of handler being the one.

Issue(s)

Further comments

it('should remove only the specified handler', () => {
    const handler = jest.fn();
    const unusedHandler = jest.fn();

    emitter.on('test', handler);
    emitter.off('test', unusedHandler);

    emitter.emit('test');

    expect(handler).toHaveBeenCalledTimes(1); // Actual: 0
    expect(unusedHandler).toHaveBeenCalledTimes(0);
  });

@tassoevan tassoevan added 🐛 Bug Something isn't working 📦 emitter labels Jul 6, 2023
@tassoevan tassoevan requested a review from a team July 6, 2023 02:03
@ggazzo ggazzo merged commit b0a603c into develop Jul 6, 2023
@ggazzo ggazzo deleted the fix/emitter-off branch July 6, 2023 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working 📦 emitter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants