UNPKG

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