Skip to content

Commit

Permalink
Fixed tests for SoundBot
Browse files Browse the repository at this point in the history
  • Loading branch information
markokajzer committed Mar 19, 2018
1 parent 51e1988 commit 91dc80b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 44 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"clean": "rm -rf dist",
"build": "tsc -p tsconfig.json",
"lint": "tslint -p tsconfig.json",
"test": "TS_NODE_TYPE_CHECK=1 nyc jasmine --config=./test/support/jasmine.json",
"test": "nyc jasmine --config=./test/support/jasmine.json",
"serve": "node dist/bot.js",
"start": "npm run build && npm run serve",
"release": "npm run build && npm run lint && npm run test"
Expand Down
46 changes: 4 additions & 42 deletions test/SoundBot.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import fs from 'fs';
import Discord from 'discord.js';

import { token, game } from '../config/config.json'
import SoundBot from '../src/SoundBot';
import MessageHandler from '../src/MessageHandler';

xdescribe('SoundBot', () => {
let bot: SoundBot;

beforeEach(() => {});
describe('SoundBot', () => {
const bot = new SoundBot();

describe('#login', () => {
beforeEach(() => {
beforeAll(() => {
spyOn(bot, 'login');
});

Expand All @@ -22,16 +16,14 @@ xdescribe('SoundBot', () => {
});

describe('#addEventListeners', () => {
beforeEach(() => {
beforeAll(() => {
spyOn((bot as any), 'setActivity');
spyOn((bot as any), 'setAvatar');
(bot as any).messageHandler = jasmine.createSpyObj('MessageHandler', ['handle']);
});

it('registers ready listeners', () => {
bot.emit('ready');
expect((bot as any).setActivity).toHaveBeenCalledTimes(1);
expect((bot as any).setAvatar).toHaveBeenCalledTimes(1);
});

it('registers message listeners', () => {
Expand All @@ -50,34 +42,4 @@ xdescribe('SoundBot', () => {
expect(bot.user.setActivity).toHaveBeenCalledWith(game);
});
});

describe('#setAvatar', () => {
describe('when avatar exists', () => {
beforeEach(() => {
spyOn(fs, 'existsSync').and.returnValue(true);
bot.user = jasmine.createSpyObj('user', ['setAvatar']);
});

it('sets the avatar', () => {
expect((bot as any).avatarExists()).toBe(true);

(bot as any).setAvatar();
expect(bot.user.setAvatar).toHaveBeenCalledWith('./config/avatar.png');
});
});

describe('when avatar does not exist', () => {
beforeEach(() => {
spyOn(fs, 'existsSync').and.returnValue(false);
bot.user = jasmine.createSpyObj('user', ['setAvatar']);
});

it('sets the avatar', () => {
expect((bot as any).avatarExists()).toBe(false);

(bot as any).setAvatar();
expect(bot.user.setAvatar).toHaveBeenCalledWith('');
});
});
});
})
2 changes: 1 addition & 1 deletion test/support/jasmine.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"**/*.test.ts"
],
"helpers": [
"support/*.js",
"support/*.ts",
"helpers/**/*.ts"
],
"stopSpecOnExpectationFailure": false,
Expand Down
File renamed without changes.

0 comments on commit 91dc80b

Please sign in to comment.