Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

144
Vistas
How to simulate receiving message from Server to Client in order to unit test SignalR client/manager with react-testing-library and jest?

I have a working SignalR manager with a connection: HubConnection that is already built with .build(). Check the following quick example:

const connection: HubConnection = new HubConnectionBuilder().withUrl(...).build();
connection.start().then(() => {
  console.log('connected');
  ...
  connection.on('PushNewMessage', (message) => addNewMessageToReduxStore(message));
  connection.on('DeleteMessage', (messageId) => deleteMessageFromStoreWithId(messageId));
  ...
});

Server sends message 'PushNewMessage' with an object with string text and number id. This triggers the addNewMessageToReduxStore(message) which is tracked for changes and trigger more Redux changes.

I want to write a unit test that starts with "Server sending a message" and compares the final Redux store state after 5 seconds since the message was received from the server to match an expected store state - then the test will pass.

So how to simulate receiving a message from the server in that exact web socket managed by the HubConnection used in the unit test initialization?

7 months ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.