Skip to content

Commit

Permalink
chore: add test package before publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
onedionys committed Mar 8, 2024
1 parent d9577f9 commit 53db524
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const assert = require('assert');
const WebSocketWrapper = require('../src/websocket-wrapper');

describe('WebSocketWrapper', () => {
let socket;

beforeEach(() => {
socket = new WebSocketWrapper('ws://localhost:8080');
});

it('should establish a WebSocket connection', (done) => {
socket.on('open', () => {
assert.strictEqual(socket.socket.readyState, WebSocket.OPEN);
done();
});
});

it('should receive messages', (done) => {
const message = 'Hello, server!';
socket.on('message', (data) => {
assert.strictEqual(data, message);
done();
});

socket.socket.onopen = () => {
socket.socket.send(message);
};
});

it('should handle errors', (done) => {
socket = new WebSocketWrapper('ws://invalid-url');
socket.on('error', (error) => {
assert(error instanceof Error);
done();
});
});
});

0 comments on commit 53db524

Please sign in to comment.