Files
dsabot/__tests__/commands/Chants.js
TobenderZephyr 79c95cea97 (dev) remove rewire, add babel-plugin-rewire. (#44)
* removed rewire. now using babel-rewire instead

* implemented more tests

* changed some eslint params

* linting

* linting

* coverage on getChant

Co-authored-by: Marcus Netz <marcus.netz@godyo.com>
2021-05-06 10:52:33 +00:00

77 lines
2.3 KiB
JavaScript

require('module-alias/register');
require('babel-plugin-rewire');
const Chants = require('@Commands/Chants');
const createChantList = Chants.__get__('createChantList');
const TestValue = {
Name: 'Test',
Level: 10,
Attributes: [
{ Name: 'Klugheit', Level: 10 },
{ Name: 'Charisma', Level: 11 },
{ Name: 'Mut', Level: 12 },
],
};
describe('createChantList', () => {
it('should return an array with expected object(s)', () => {
const Test = { chants: [{ id: 'test', level: 10 }] };
const expected = {
Name: 'Test',
Level: 10,
Attributes: [
{ Name: 'Klugheit', Level: 10 },
{ Name: 'Charisma', Level: 11 },
{ Name: 'Mut', Level: 12 },
],
};
Chants.__Rewire__('getChant', () => expected);
expect(createChantList(Test)).toEqual(expect.arrayContaining([expected]));
Chants.__ResetDependency__('getChant');
});
it('should abort if character has no chants', () => {
expect(createChantList({ attributes: [] })).toBeNull();
expect(createChantList()).toBeNull();
expect(createChantList({})).toBeNull();
});
});
describe('ReplyChant', () => {
const ReplyChant = Chants.__get__('ReplyChant');
it('should return null if no param given.', () => {
expect(ReplyChant()).toBeNull();
});
it('should return a string', () => {
// toBeInstanceOf(String) is not working :(
expect(
ReplyChant({
Name: 'Test',
Level: 9,
Attributes: [
{ Name: 'Klugheit', Level: 10 },
{ Name: 'Charisma', Level: 11 },
{ Name: 'Mut', Level: 12 },
],
})
).toMatch(/.*Test.*(9)?.*/);
});
Chants.__ResetDependency__('ReplyChant');
});
describe('ReplyChantList', () => {
const ReplyChantList = Chants.__get__('ReplyChantList');
it('should return null if params are empty', () => {
expect(ReplyChantList('')).toBeNull();
expect(ReplyChantList([])).toBeNull();
expect(ReplyChantList()).toBeNull();
});
it('should return Name and Level', () => {
const input = [TestValue];
expect(ReplyChantList(input)).toMatch('Test (10)');
});
});