From 6d3385aa8831b26142ad2218fc40303aa843f278 Mon Sep 17 00:00:00 2001 From: Felix Hamann Date: Mon, 27 May 2019 20:11:27 +0200 Subject: [PATCH] add unit test for main frontend application --- frontend/src/app.spec.js | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 frontend/src/app.spec.js diff --git a/frontend/src/app.spec.js b/frontend/src/app.spec.js new file mode 100644 index 000000000..8ce962b2d --- /dev/null +++ b/frontend/src/app.spec.js @@ -0,0 +1,52 @@ +import { App } from "./app"; + +const TEST_UTILS = [ + { name: 'util1' }, + { name: 'util2' }, +]; + +describe('App', () => { + let app; + + beforeEach(() => { + app = new App(); + }); + + it('should create', () => { + expect(app).toBeTruthy(); + }); + + describe('provides services', () => { + it('HttpClient as httpClient', () => { + expect(app.httpClient).toBeTruthy(); + }); + + it('HtmlHelpers as htmlHelpers', () => { + expect(app.htmlHelpers).toBeTruthy(); + }); + + it('I18n as i18n', () => { + expect(app.i18n).toBeTruthy(); + }); + + it('UtilRegistry as utilRegistry', () => { + expect(app.utilRegistry).toBeTruthy(); + }); + }); + + describe('registerUtilities()', () => { + it('should register the given utilities', () => { + spyOn(app.utilRegistry, 'register'); + app.registerUtilities(TEST_UTILS); + expect(app.utilRegistry.register.calls.count()).toBe(TEST_UTILS.length); + expect(app.utilRegistry.register.calls.argsFor(0)).toEqual([TEST_UTILS[0]]); + expect(app.utilRegistry.register.calls.argsFor(1)).toEqual([TEST_UTILS[1]]); + }); + + it('should throw an error if not passed an array of utilities', () => { + expect(() => { + app.registerUtilities({}); + }).toThrow(); + }); + }); +});