Skip to content
This repository has been archived by the owner on Jun 10, 2021. It is now read-only.

Commit

Permalink
test(page-renderer): added test for component utils
Browse files Browse the repository at this point in the history
  • Loading branch information
VojtaSim committed Aug 16, 2019
1 parent 9ae2ad2 commit f3d3e63
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions page/renderer/__tests__/ComponentUtilsSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { toMockedInstance } from 'to-mock';

import ObjectContainer from 'ObjectContainer';
import ComponentUtils from 'page/renderer/ComponentUtils';

class SomeMockHelper {}

class SomeHelper {}

describe('ComponentUtils', () => {
let componentUtils = null;

const oc = toMockedInstance(ObjectContainer);

beforeEach(() => {
componentUtils = new ComponentUtils(oc);
});

describe('register() method', () => {
it('should register utility class under its own real name.', () => {
componentUtils.register(SomeMockHelper);

expect(componentUtils._utilities['SomeMockHelper']).not.toBeUndefined();
expect(componentUtils._utilities['SomeMockHelper']).toEqual(
SomeMockHelper
);
});

it('should register utility class under given alias.', () => {
componentUtils.register(SomeMockHelper, 'MockHelper');

expect(componentUtils._utilities['MockHelper']).not.toBeUndefined();
expect(componentUtils._utilities['MockHelper']).toEqual(SomeMockHelper);
});

it('should register multiple classes given in form of an Object.', () => {
componentUtils.register({
MockHelper: SomeMockHelper,
SomeHelper
});

expect(componentUtils._utilities['MockHelper']).toEqual(SomeMockHelper);
expect(componentUtils._utilities['SomeHelper']).toEqual(SomeHelper);
});
});

describe('getUtils() method.', () => {
beforeEach(() => {
spyOn(oc, 'get').and.callFake(entity =>
typeof entity === 'function' ? new entity() : entity
);

componentUtils.register({
SomeMockHelper,
SomeHelper
});
});

it('should return $Utils constant from OC if created.', () => {
spyOn(oc, 'has').and.callFake(entity => entity === '$Utils');

componentUtils.getUtils();

expect(oc.get).toHaveBeenCalledWith('$Utils');
});

it('should create instace of each registered class through OC.', () => {
const utils = componentUtils.getUtils();

expect(oc.get).toHaveBeenCalledTimes(2);
expect(utils['SomeHelper'] instanceof SomeHelper).toBeTruthy();
expect(utils['SomeMockHelper'] instanceof SomeMockHelper).toBeTruthy();
});
});
});

0 comments on commit f3d3e63

Please sign in to comment.