Event Tests

This commit is contained in:
Vylpes 2021-02-13 18:07:18 +00:00
parent 893c0e1675
commit 21711c66ad
2 changed files with 42 additions and 0 deletions

View file

@ -31,6 +31,8 @@ class event {
"message": message "message": message
}; };
} }
return false;
} }
// Emit when bot is logged in and ready to use // Emit when bot is logged in and ready to use

View file

@ -1,5 +1,6 @@
const events = require('../../../src/client/events'); const events = require('../../../src/client/events');
const { readFileSync } = require('fs'); const { readFileSync } = require('fs');
const { expect } = require('@jest/globals');
// Mocks // Mocks
jest.mock('discord.js'); jest.mock('discord.js');
@ -86,4 +87,43 @@ describe('events.message', () => {
instance.message(message) instance.message(message)
}).not.toThrow(); }).not.toThrow();
}); });
test('Should return if message doesnt have prefix', () => {
message.content = "Just a normal message";
const res = instance.message(message);
expect(res).toBe(false);
});
});
describe('events.ready', () => {
let instance;
let message;
let config;
beforeEach(() => {
instance = new events();
message = JSON.parse(readFileSync('tests/json/message.json'));
config = JSON.parse(readFileSync('tests/json/config.json'));
instance.config = config;
instance.util = jest.fn();
instance.util.loadCommand = jest.fn(() => {
return {
"valid": true,
"message": "No message was set"
}
});
console = jest.fn();
console.log = jest.fn();
});
test('Should log when ready', () => {
const res = instance.ready();
expect(console.log).toHaveBeenCalledTimes(1);
expect(console.log).toHaveBeenCalledWith("Ready");
});
}); });