index.js 1.0 KB

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. var test = require('tape');
  3. var domify = require('domify');
  4. var matches = require('../');
  5. var ul = domify('<ul><li><em>foo</em></li></ul>');
  6. var li = ul.children[0];
  7. var em = li.children[0];
  8. test('matchesSelector(el, selector)', function (t) {
  9. t.plan(12);
  10. t.assert(true === matches(em, 'ul li em'), 'em = "ul li em"');
  11. t.assert(true === matches(em, 'ul em'), 'em = "ul em"');
  12. t.assert(true === matches(em, 'ul > li > em'), 'em = "ul > li > em"');
  13. t.assert(false === matches(em, 'ul ul em'), 'em != "ul ul em"');
  14. t.assert(true === matches(li, 'ul li'), 'li = "ul li"');
  15. t.assert(true === matches(li, 'ul > li'), 'li = "ul > li"');
  16. t.assert(true === matches(li, 'li'), 'li = "li"');
  17. t.assert(false === matches(li, 'div > li'), 'li != "div > li"');
  18. t.assert(true == matches(ul, 'ul', 'ul = "ul"'), 'ul = "ul"');
  19. t.assert(false == matches(ul, 'body > ul'), 'ul != "body > ul"');
  20. t.assert(false === matches(em.firstChild, 'ul'), 'match on textNode is false');
  21. t.assert(false === matches(null, 'ul'), 'match on null is false');
  22. })