matches.test.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { matches } from './matches';
  2. describe( 'children', () => {
  3. beforeEach( () => {
  4. document.body.innerHTML = `
  5. <div id="container">
  6. <span id="span1" class="active"></span>
  7. <button id="button1" class="active"></button>
  8. <span id="span2"></span>
  9. <button id="button2"></button>
  10. <span id="span3"></span>
  11. <button id="button3"></button>
  12. </div>
  13. `;
  14. } );
  15. test( 'can test if the selector matches the element or not.', () => {
  16. const container = document.getElementById( 'container' );
  17. expect( matches( container, 'div' ) ).toBe( true );
  18. expect( matches( container, '#container' ) ).toBe( true );
  19. expect( matches( container, 'span' ) ).toBe( false );
  20. const span = container.firstElementChild;
  21. expect( matches( span, 'span' ) ).toBe( true );
  22. expect( matches( span, '#span1' ) ).toBe( true );
  23. expect( matches( span, '.active' ) ).toBe( true );
  24. expect( matches( span, '#container .active' ) ).toBe( true );
  25. expect( matches( span, '#container' ) ).toBe( false );
  26. expect( matches( span, '#span2' ) ).toBe( false );
  27. } );
  28. } );