Testing
Jest Mock
jest.mock('@kesha-antonov/react-native-action-cable', () => ({
ActionCable: {
createConsumer: jest.fn(() => ({
subscriptions: {
create: jest.fn(() => ({
on: jest.fn().mockReturnThis(),
removeListener: jest.fn().mockReturnThis(),
perform: jest.fn(),
unsubscribe: jest.fn(),
})),
},
connection: {
isActive: jest.fn(() => true),
isOpen: jest.fn(() => true),
},
disconnect: jest.fn(),
})),
},
Cable: jest.fn(() => ({
channels: {},
channel: jest.fn(),
setChannel: jest.fn(),
})),
}))
See examples/testing for complete testing examples.
Testing this library
The library itself is covered by a Jest suite in __tests__, which
drives the real connection code against a WebSocket double that behaves like a
Rails ActionCable server:
yarn test # run the suite
yarn test:coverage # run it with a coverage report
yarn typecheck # type-check the library and the tests