describe('Bridge', () => {
let Bridge;
beforeEach(() => {
Bridge = require('react-devtools-shared/src/bridge').default;
});
it('should shutdown properly', () => {
const wall = {
listen: jest.fn(() => () => {}),
send: jest.fn(),
};
const bridge = new Bridge(wall);
const shutdownCallback = jest.fn();
bridge.addListener('shutdown', shutdownCallback);
bridge.send('reloadAppForProfiling');
jest.runAllTimers();
expect(wall.send).toHaveBeenCalledWith('reloadAppForProfiling');
wall.send.mockClear();
bridge.send('update', '1');
bridge.send('update', '2');
bridge.shutdown();
jest.runAllTimers();
expect(wall.send).toHaveBeenCalledWith('update', '1');
expect(wall.send).toHaveBeenCalledWith('update', '2');
expect(wall.send).toHaveBeenCalledWith('shutdown');
expect(shutdownCallback).toHaveBeenCalledTimes(1);
jest.spyOn(console, 'warn').mockImplementation(() => {});
wall.send.mockClear();
bridge.send('should not send');
jest.runAllTimers();
expect(wall.send).not.toHaveBeenCalled();
expect(console.warn).toHaveBeenCalledWith(
'Cannot send message "should not send" through a Bridge that has been shutdown.',
);
});
});