tests.js 1.5 KB

123456789101112131415161718192021222324252627282930
  1. test( 'matchesSelector', function() {
  2. equal( typeof matchesSelector, 'function', 'typeof is function' );
  3. var alpha = document.getElementById('alpha');
  4. equal( matchesSelector( alpha, '#alpha' ), true, '[#alpha] matches #alpha' );
  5. equal( matchesSelector( alpha, '.item' ), true, '[#alpha] matches .item' );
  6. equal( matchesSelector( alpha, 'div' ), true, '[#alpha] matches div' );
  7. equal( matchesSelector( alpha, 'p' ), false, '[#alpha] does not match p' );
  8. equal( matchesSelector( alpha, '.baz' ), false, '[#alpha] does not match .baz' );
  9. equal( matchesSelector( alpha, '#alpha.item' ), true, '[#alpha] matches #alpha.item' );
  10. equal( matchesSelector( alpha, '#alpha, foo'), true, '[#alpha] matches #alpha, foo' );
  11. equal( matchesSelector( alpha, 'foo, .item'), true, '[#alpha] matches foo, .item' );
  12. // orphaned elem
  13. var beta = document.createElement('div');
  14. beta.id = 'beta';
  15. beta.className = 'foo bar';
  16. equal( matchesSelector( beta, 'div' ), true, '[#beta] matches div' );
  17. equal( matchesSelector( beta, '#beta' ), true, '[#beta] matches #beta' );
  18. equal( matchesSelector( beta, '.bar' ), true, '[#beta] matches .bar' );
  19. equal( matchesSelector( beta, 'p' ), false, '[#beta] does not match p' );
  20. equal( matchesSelector( beta, '.baz' ), false, '[#beta] does not match .baz' );
  21. equal( matchesSelector( beta, '#beta.bar' ), true, '[#alpha] matches #alpha.item' );
  22. equal( matchesSelector( beta, '#beta, qux' ), true, '[#beta] matches #beta, qux' );
  23. equal( matchesSelector( beta, '.qux, .bar'), true, '[#alpha] matches .qux, .bar' );
  24. });