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 false if className not defined', () => {
expect(hasClass({}, undefined)).toEqual(false);
});
it('should return false if element not defined', () => {
expect(hasClass(undefined, 'test')).toEqual(false);
});
it('should return true if className found', () => {
element.className = 'class';
expect(hasClass(element, 'class')).toEqual(true);
});
});
it('should call classList contains()', () => {
const spy = jest.spyOn(element.classList, 'contains');
hasClass(element, 'other');
expect(spy).toHaveBeenCalled();
});
});
it('should return false if className not found', () => {
element.className = 'class';
expect(hasClass(element, 'other')).toEqual(false);
});
expect(() => hasClass({}, 'class1 class2')).toThrowError();
});