Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime config unit tests #854

Merged
merged 1 commit into from
Jun 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});