Skip to content

Commit

Permalink
Manual initializer tests (#858)
Browse files Browse the repository at this point in the history
Unit tests for the manual initializer

J=SLAP-1371
TEST=auto
  • Loading branch information
cea2aj committed Jun 28, 2021
1 parent fb78175 commit 6402079
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/static/js/manual-initializer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import ManualInitializer from '../../../static/js/manual-initializer';

describe('The manual initializer works', () => {
let initAnswers;

beforeEach(() => {
window.AnswersExperience = {
runtimeConfig: {
get: jest.fn(),
set: jest.fn()
}
};
initAnswers = jest.fn();
const manualInitializer = new ManualInitializer(initAnswers);
manualInitializer.setup();
})

it('The manual init function calls initAnswers', () => {
window.AnswersExperience.init();
expect(initAnswers).toHaveBeenCalledTimes(1);
});

it('Data passed into the init function is set on the runtimeConfig', () => {
window.AnswersExperience.init({
token: '123abc',
linkTarget: '_blank'
});
const runtimeConfigSet = window.AnswersExperience.runtimeConfig.set;
expect(runtimeConfigSet).toHaveBeenCalledWith('token', '123abc');
expect(runtimeConfigSet).toHaveBeenCalledWith('linkTarget', '_blank');
});
});

0 comments on commit 6402079

Please sign in to comment.