events-test.js — react Source File
Architecture documentation for events-test.js, a javascript file in the react codebase.
Entity Profile
Source Code
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
describe('events', () => {
let dispatcher;
beforeEach(() => {
const EventEmitter = require('../events').default;
dispatcher = new EventEmitter();
});
// @reactVersion >=16
it('can dispatch an event with no listeners', () => {
dispatcher.emit('event', 123);
});
// @reactVersion >=16
it('handles a listener being attached multiple times', () => {
const callback = jest.fn();
dispatcher.addListener('event', callback);
dispatcher.addListener('event', callback);
dispatcher.emit('event', 123);
expect(callback).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledWith(123);
});
// @reactVersion >=16
it('notifies all attached listeners of events', () => {
const callback1 = jest.fn();
const callback2 = jest.fn();
const callback3 = jest.fn();
dispatcher.addListener('event', callback1);
dispatcher.addListener('event', callback2);
dispatcher.addListener('other-event', callback3);
dispatcher.emit('event', 123);
expect(callback1).toHaveBeenCalledTimes(1);
expect(callback1).toHaveBeenCalledWith(123);
expect(callback2).toHaveBeenCalledTimes(1);
expect(callback2).toHaveBeenCalledWith(123);
expect(callback3).not.toHaveBeenCalled();
});
// @reactVersion >= 16.0
it('calls later listeners before re-throwing if an earlier one throws', () => {
const callbackThatThrows = jest.fn(() => {
throw Error('expected');
});
const callback = jest.fn();
// ... (74 more lines)
Source
Frequently Asked Questions
What does events-test.js do?
events-test.js is a source file in the react codebase, written in javascript.
Where is events-test.js in the architecture?
events-test.js is located at packages/react-devtools-shared/src/__tests__/events-test.js (directory: packages/react-devtools-shared/src/__tests__).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free