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 not add class if class already exists', () => {
element.className = 'test';
addClass(element, 'test');
expect(element.className).toEqual('test');
});
it('should return if element not provided', () => {
expect(addClass(undefined, undefined)).toEqual(undefined);
});
it('should add a class', () => {
addClass(element, 'class');
expect(element.className).toEqual(' class');
});
it('should add multiple classes', () => {
const spy = jest.spyOn(element.classList, 'add');
addClass(element, 'class1 class2');
expect(spy).toHaveBeenCalledTimes(2);
expect(spy).toHaveBeenCalledWith('class1');
expect(spy).toHaveBeenCalledWith('class2');
});
});
it('should not add any class if classes not provided', () => {
addClass(element, '');
expect(element.className).toEqual(undefined);
});