Add tests for hideIf

This commit is contained in:
MareStare 2025-03-12 00:56:26 +00:00
parent c9f3677bd4
commit 007a3e629a

View file

@ -14,6 +14,7 @@ import {
findFirstTextNode, findFirstTextNode,
disableEl, disableEl,
enableEl, enableEl,
hideIf,
} from '../dom'; } from '../dom';
import { getRandomArrayItem, getRandomIntBetween } from '../../../test/randomness'; import { getRandomArrayItem, getRandomIntBetween } from '../../../test/randomness';
import { fireEvent } from '@testing-library/dom'; import { fireEvent } from '@testing-library/dom';
@ -444,4 +445,18 @@ describe('DOM Utilities', () => {
expect(result).toBe(undefined); expect(result).toBe(undefined);
}); });
}); });
describe('hideIf', () => {
it('should add "hidden" class if condition is true', () => {
const element = document.createElement('div');
hideIf(true, element);
expect(element).toHaveClass('hidden');
});
it('should remove "hidden" class if condition is false', () => {
const element = document.createElement('div');
element.classList.add('hidden');
hideIf(false, element);
expect(element).not.toHaveClass('hidden');
});
});
}); });