UNPKG

1.08 kBJavaScriptView Raw
1
2var matches = require('matches-selector')
3 , domify = require('domify');
4
5function assert(expr) {
6 if (!expr) throw new Error('assertion failed');
7}
8
9var ul = domify('<ul><li><em>foo</em></li></ul>');
10var li = ul.children[0];
11var em = li.children[0];
12
13describe('matchesSelector(el, selector)', function(){
14 it('should work', function(){
15 assert(true === matches(em, 'ul li em'));
16 assert(true === matches(em, 'ul em'));
17 assert(true === matches(em, 'ul > li > em'));
18 assert(false === matches(em, 'ul ul em'));
19
20 assert(true === matches(li, 'ul li'));
21 assert(true === matches(li, 'ul > li'));
22 assert(true === matches(li, 'li'));
23 assert(false === matches(li, 'div > li'));
24
25 assert(true == matches(ul, 'ul'));
26 assert(false == matches(ul, 'div ul'));
27 assert(false == matches(ul, 'body > ul'));
28 })
29 it('should not throw an Error when given `null`', function(){
30 assert(false == matches(null, 'ul'));
31 })
32 it('should not throw an Error when given a TextNode', function(){
33 assert(false == matches(em.firstChild, 'ul'));
34 })
35})