Commit 9f54bb78 authored by Peter Hegman's avatar Peter Hegman Committed by jejacks0n

Add tests for ready state

parent 9855f4fd
......@@ -207,6 +207,42 @@ describe('Tracking', () => {
[],
);
});
describe('when `document.readyState` does not equal `complete`', () => {
const originalReadyState = document.readyState;
const setReadyState = (value) => {
Object.defineProperty(document, 'readyState', {
value,
configurable: true,
});
};
const fireReadyStateChangeEvent = () => {
document.dispatchEvent(new Event('readystatechange'));
};
beforeEach(() => {
setReadyState('interactive');
});
afterEach(() => {
setReadyState(originalReadyState);
});
it('does not call `window.snowplow` until `readystatechange` is fired and `document.readyState` equals `complete`', () => {
Tracking.enableFormTracking({ fields: { allow: ['input-class1'] } });
expect(snowplowSpy).not.toHaveBeenCalled();
fireReadyStateChangeEvent();
expect(snowplowSpy).not.toHaveBeenCalled();
setReadyState('complete');
fireReadyStateChangeEvent();
expect(snowplowSpy).toHaveBeenCalled();
});
});
});
describe('.flushPendingEvents', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment