Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should return if classes not provided', () => {
expect(removeClass(true, undefined)).toEqual(undefined);
});
it('should return if element not provided', () => {
expect(removeClass(undefined, undefined)).toEqual(undefined);
});
it('should add a class', () => {
const spy = jest.spyOn(element.classList, 'remove');
removeClass(element, 'class');
expect(spy).toHaveBeenCalled();
expect(spy).toHaveBeenCalledWith('class');
});
it('should continue if empty string given', () => {
element.className = 'class1 class2';
removeClass(element, ' ');
expect(element.className).toEqual('class1 class2');
});
});
it('should not remove class if class doesn\'t exist', () => {
element.className = 'other';
removeClass(element, 'test');
expect(element.className).toEqual('other');
});
it('should ignore double spaces', () => {
element.className = 'class1 class2';
removeClass(element, 'class1');
expect(element.className).toEqual('class2');
});
it('should remove multiple classes', () => {
const spy = jest.spyOn(element.classList, 'remove');
removeClass(element, 'class1 class2');
expect(spy).toHaveBeenCalledTimes(2);
expect(spy).toHaveBeenCalledWith('class1');
expect(spy).toHaveBeenCalledWith('class2');
});
});