open-index/open-npm huggingface dataset:
npm package: @jmredfern/websocket-with-promises
Description: This is a utility that wraps the ws WebSocket library with promises. This is useful for creating component tests for applications that use WebSockets.
Author: Jim Redfern
Latest version: 1.0.4

# websocket-with-promises

This is a utility that wraps the ws WebSocket library with promises. This is useful for creating component tests for
applications that use WebSockets.

---

## Example Usage

```js
import { getWebSocket, WebSocket } from 'websocket-with-promises';

describe('component test', () => {
	const websocket = getWebSocket({ URL: 'ws://localhost:8000' });

	beforeAll(async () => {
		await websocket.connect();
	});

	afterAll(async () => {
		await websocket.disconnect();
	});

	it('should create a game', async () => {
		await websocket.sendMessageAsJSON({ type: 'CREATE_GAME' });
		const serverMessage = await websocket.getMessageAsObject();
		expect(serverMessage).toEqual({ type: 'GAME_CREATED' });
	});
});
```

---

### To run the test suite:

`npm run test`

---

## License

MIT © [Jim Redfern]().

[npm-image]: https://badge.fury.io/js/button-clicker.svg
[npm-url]: https://npmjs.org/package/button-clicker
[travis-image]: https://travis-ci.com/jmredfern/button-clicker.svg?branch=master
[travis-url]: https://travis-ci.com/jmredfern/button-clicker
[daviddm-image]: https://david-dm.org/jmredfern/button-clicker.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/jmredfern/button-clicker
[coveralls-image]: https://coveralls.io/repos/jmredfern/button-clicker/badge.svg
[coveralls-url]: https://coveralls.io/r/jmredfern/button-clicker