Jest: mocking socket

Created on 18 Sep 2016  路  4Comments  路  Source: facebook/jest

is there anyway to mock socket with jest?

basically my app is a 2 player game, whereby the first player creates a room, and then wait for player 2 to join (player 2 have to enter the game code provided by player 1 manually) before the navigator proceeds to the next scene which is the actual game.

However, I cannot proceed to the second scene until the player 2 enter the pin. In this case, I need to mock to player 1 and let him assume that player 2 has already join the room.

I not sure how to do that with jest

Most helpful comment

Is there any working example on how to simulate a websocket server and mock data with jest?

All 4 comments

Any JavaScript function can be mocked simply by doing myModule.myFunction = jest.fn() or using myModule.myFunction = jest.fn(() => mockReturnValue);.

Is there any working example on how to simulate a websocket server and mock data with jest?

@ablanco1492 I don't know of any example, but Stack Overflow is the best place to ask such questions!

Was this page helpful?
0 / 5 - 0 ratings