BigW Consortium Gitlab

fixed and added specs for removing placeholder element

parent 7ce70dd5
......@@ -4,12 +4,25 @@ describe('sticky', () => {
const el = {
offsetTop: 0,
classList: {},
parentNode: {},
nextElementSibling: {},
};
let isStuck = false;
beforeEach(() => {
el.offsetTop = 0;
el.classList.add = jasmine.createSpy('spy');
el.classList.remove = jasmine.createSpy('spy');
el.classList.add = jasmine.createSpy('classListAdd');
el.classList.remove = jasmine.createSpy('classListRemove');
el.classList.contains = jasmine.createSpy('classListContains').and.callFake(() => isStuck);
el.parentNode.insertBefore = jasmine.createSpy('insertBefore');
el.nextElementSibling.remove = jasmine.createSpy('nextElementSibling');
el.nextElementSibling.classList = {
contains: jasmine.createSpy('classListContains').and.returnValue(true),
};
});
afterEach(() => {
isStuck = false;
});
describe('classList.remove', () => {
......@@ -21,7 +34,9 @@ describe('sticky', () => {
).not.toHaveBeenCalled();
});
it('calls classList.remove when not stuck', () => {
it('calls classList.remove when no longer stuck', () => {
isStuck = true;
el.offsetTop = 10;
isSticky(el, 0, 0);
......@@ -29,6 +44,17 @@ describe('sticky', () => {
el.classList.remove,
).toHaveBeenCalledWith('is-stuck');
});
it('removes placeholder when no longer stuck', () => {
isStuck = true;
el.offsetTop = 10;
isSticky(el, 0, 0, true);
expect(
el.nextElementSibling.remove,
).toHaveBeenCalled();
});
});
describe('classList.add', () => {
......@@ -48,5 +74,13 @@ describe('sticky', () => {
el.classList.add,
).not.toHaveBeenCalled();
});
it('inserts placeholder element when stuck', () => {
isSticky(el, 0, 0, true);
expect(
el.parentNode.insertBefore,
).toHaveBeenCalled();
});
});
});
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