Skip to content

Commit

Permalink
Runtime config unit tests (#854)
Browse files Browse the repository at this point in the history
Add unit tests to the runtime config model

J=SLAP-1371
TEST=auto
  • Loading branch information
cea2aj committed Jun 28, 2021
1 parent 0f39c75 commit 4313bce
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/static/js/runtime-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import RuntimeConfig from '../../../static/js/runtime-config';

describe('Runtime config data model functionality', () => {
it('Can set and get data', () => {
const runtimeConfig = new RuntimeConfig();
runtimeConfig.set('linkTarget', '_blank');
const linkTarget = runtimeConfig.get('linkTarget');
expect(linkTarget).toEqual('_blank');
});

it('The getAll function works', () => {
const runtimeConfig = new RuntimeConfig();
runtimeConfig.set('linkTarget', '_blank');
runtimeConfig.set('color', 'red');
const actualData = runtimeConfig.getAll();
const expectedData = {
linkTarget: '_blank',
color: 'red'
};
expect(actualData).toEqual(expectedData);
});

it('The _onUpdate callback is called when data is set', () => {
const runtimeConfig = new RuntimeConfig();
const mockCallback = jest.fn();
runtimeConfig._onUpdate(mockCallback);
runtimeConfig.set('linkTarget', '_blank');
expect(mockCallback).toHaveBeenCalled();
});

it('An error is thrown if the setter receives data which is not JSON serializable', () => {
const runtimeConfig = new RuntimeConfig();
const setNonSerializableData = () => {
const circularReference = {};
circularReference.myself = circularReference;
runtimeConfig.set('linkTarget', circularReference);
};
expect(setNonSerializableData).toThrowError();
});
});

0 comments on commit 4313bce

Please sign in to comment.