1 | let both = require('../both');
|
2 | let sinonChai = require('sinon-chai');
|
3 | let sinon = require('sinon');
|
4 | let chai = require('chai');
|
5 | chai.use(sinonChai);
|
6 | let expect = chai.expect;
|
7 |
|
8 | describe('Register Module', () => {
|
9 |
|
10 | describe('Error handling', () => {
|
11 |
|
12 | it('throws an error if no argument is given', () => {
|
13 | expect(() => {
|
14 | both.register();
|
15 | }).to.throw(Error);
|
16 | });
|
17 |
|
18 | it('throws an error if the first argument isnt a string', () => {
|
19 | expect(() => {
|
20 | both.register([], {});
|
21 | }).to.throw(Error);
|
22 | });
|
23 |
|
24 | it('throws an error if the second argument isnt a object', () => {
|
25 | expect(() => {
|
26 | both.register('dummyRegisterType', 'notAllowedSecondArg');
|
27 | }).to.throw(Error);
|
28 | });
|
29 |
|
30 | it('throws an error if no `name` param is in the payload given', () => {
|
31 | expect(() => {
|
32 | both.register('dummyRegisterType', {
|
33 | no: 'nameParamGiven'
|
34 | });
|
35 | }).to.throw(Error);
|
36 | });
|
37 |
|
38 | });
|
39 |
|
40 | describe('Register Types', () => {
|
41 |
|
42 | beforeEach(() => {
|
43 | both._globalRegistery = {};
|
44 | });
|
45 |
|
46 | it('registers correct the registerName in the globalRegistery', () => {
|
47 | both._globalRegistery = {};
|
48 | both.register('dummyCommands', {
|
49 | name: 'dummyCommandName'
|
50 | });
|
51 |
|
52 | expect(both._globalRegistery).to.deep.equal({
|
53 | dummyCommands: {
|
54 | dummyCommandName: {
|
55 | name: 'dummyCommandName'
|
56 | }
|
57 | }
|
58 | });
|
59 | });
|
60 |
|
61 | it('registers correct the payload with all object-childrens', () => {
|
62 | both._globalRegistery = {};
|
63 | both.register('dummyCommands', {
|
64 | name: 'dummyCommandName',
|
65 | some: 'param'
|
66 | });
|
67 |
|
68 | expect(both._globalRegistery).to.deep.equal({
|
69 | dummyCommands: {
|
70 | dummyCommandName: {
|
71 | name: 'dummyCommandName',
|
72 | some: 'param'
|
73 | }
|
74 | }
|
75 | });
|
76 | });
|
77 |
|
78 | });
|
79 |
|
80 | });
|