Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add jest round2 #37

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions __test__/background.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import browser from 'webextension-polyfill';
import socketConnect from '../src/background/socket';
import gameStatuses from '../src/background/models';
import phxReply4bots from '../__fixtures__/phxReply4bots';
import getUpdateResponseWithID from '../__fixtures__/getUpdateResponse';
import getRemoveResponseWithID from '../__fixtures__/getRemoveResponse';

describe('socket', () => {
const fakeSocket = {};
socketConnect(('wss://codebattle.hexlet.io/extension/websocket?vsn=2.0.0'), fakeSocket);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если честно, я пока не понял как эта штука сработала.
Ощущение что либо у нас неправильно сделан socketConnect, либо где-то идёт мухлеж с кодом

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну не мухлеж... Все по заветам хекслета. Это идея из продвинутого тестирования. Сущность сокета по умолчанию устанавливается, и если явно не передать в socketConnect


test('phxReply', () => {
fakeSocket.onmessage(phxReply4bots);
expect(browser.browserAction.setBadgeText).toHaveBeenLastCalledWith({
text: null,
});
});
test('add games->remove games', () => {
fakeSocket.onmessage(getUpdateResponseWithID(1000, gameStatuses.waiting));
expect(browser.browserAction.setBadgeText).toHaveBeenLastCalledWith({
text: '1',
});
fakeSocket.onmessage(getUpdateResponseWithID(1001, gameStatuses.waiting));
expect(browser.browserAction.setBadgeText).toHaveBeenLastCalledWith({
text: '2',
});
fakeSocket.onmessage(getRemoveResponseWithID(1001));
expect(browser.browserAction.setBadgeText).toHaveBeenLastCalledWith({
text: '1',
});
fakeSocket.onmessage(getRemoveResponseWithID(1000));
expect(browser.browserAction.setBadgeText).toHaveBeenLastCalledWith({
text: null,
});
});
test('add game -> changeStatus', () => {
fakeSocket.onmessage(getUpdateResponseWithID(1002, gameStatuses.waiting));
expect(browser.browserAction.setBadgeText).toHaveBeenLastCalledWith({
text: '1',
});
fakeSocket.onmessage(getUpdateResponseWithID(1002, gameStatuses.joined));
expect(browser.browserAction.setBadgeText).toHaveBeenLastCalledWith({
text: null,
});
});
});