|
1 |
| -/** |
2 |
| - * @author Titus Wormer |
3 |
| - * @copyright 2016 Titus Wormer |
4 |
| - * @license MIT |
5 |
| - * @module hast:util:is-element |
6 |
| - * @fileoverview Test suite for `is-element`. |
7 |
| - */ |
8 |
| - |
9 | 1 | 'use strict';
|
10 | 2 |
|
11 |
| -/* eslint-env node */ |
12 |
| - |
13 |
| -/* |
14 |
| - * Module dependencies. |
15 |
| - */ |
16 |
| - |
| 3 | +/* Dependencies. */ |
17 | 4 | var test = require('tape');
|
18 | 5 | var isElement = require('./index.js');
|
19 | 6 |
|
20 |
| -/* |
21 |
| - * Tests. |
22 |
| - */ |
23 |
| - |
| 7 | +/* Tests. */ |
24 | 8 | test('isElement', function (t) {
|
25 |
| - t.equal(isElement(), false, 'should return `false` without node'); |
26 |
| - t.equal(isElement(null), false, 'should return `false` with `null`'); |
27 |
| - |
28 |
| - t.throws( |
29 |
| - function () { |
30 |
| - isElement(null, true) |
31 |
| - }, |
32 |
| - 'Expected `string` or `Array.<string>` for `tagNames`, not `true`', |
33 |
| - 'should throw when the second parameter is invalid' |
| 9 | + t.equal(isElement(), false, 'should return `false` without node'); |
| 10 | + t.equal(isElement(null), false, 'should return `false` with `null`'); |
| 11 | + |
| 12 | + t.throws( |
| 13 | + function () { |
| 14 | + isElement(null, true); |
| 15 | + }, |
| 16 | + 'Expected `string` or `Array.<string>` for `tagNames`, not `true`', |
| 17 | + 'should throw when the second parameter is invalid' |
| 18 | + ); |
| 19 | + |
| 20 | + t.test('isElement(node)', function (st) { |
| 21 | + st.equal( |
| 22 | + isElement({type: 'text'}), |
| 23 | + false, |
| 24 | + 'should return `false` when without `element`' |
| 25 | + ); |
| 26 | + |
| 27 | + st.equal( |
| 28 | + isElement({type: 'element'}), |
| 29 | + false, |
| 30 | + 'should return `false` when with invalid `element`' |
| 31 | + ); |
| 32 | + |
| 33 | + st.equal( |
| 34 | + isElement({type: 'element', tagName: 'div'}), |
| 35 | + true, |
| 36 | + 'should return `true` when with valid `element`' |
| 37 | + ); |
| 38 | + |
| 39 | + st.end(); |
| 40 | + }); |
| 41 | + |
| 42 | + t.test('isElement(node, tagName)', function (st) { |
| 43 | + st.equal( |
| 44 | + isElement({type: 'text'}, 'div'), |
| 45 | + false, |
| 46 | + 'should return `false` when without `element`' |
| 47 | + ); |
| 48 | + |
| 49 | + st.equal( |
| 50 | + isElement({type: 'element'}, 'div'), |
| 51 | + false, |
| 52 | + 'should return `false` when with invalid `element`' |
| 53 | + ); |
| 54 | + |
| 55 | + st.equal( |
| 56 | + isElement({type: 'element', tagName: 'strong'}, 'div'), |
| 57 | + false, |
| 58 | + 'should return `false` when without matching `element`' |
34 | 59 | );
|
35 | 60 |
|
36 |
| - t.test('isElement(node)', function (st) { |
37 |
| - st.equal(isElement({ |
38 |
| - 'type': 'text' |
39 |
| - }), false, 'should return `false` when without `element`'); |
40 |
| - |
41 |
| - st.equal(isElement({ |
42 |
| - 'type': 'element' |
43 |
| - }), false, 'should return `false` when with invalid `element`'); |
44 |
| - |
45 |
| - st.equal(isElement({ |
46 |
| - 'type': 'element', |
47 |
| - 'tagName': 'div' |
48 |
| - }), true, 'should return `true` when with valid `element`'); |
49 |
| - |
50 |
| - st.end(); |
51 |
| - }); |
52 |
| - |
53 |
| - t.test('isElement(node, tagName)', function (st) { |
54 |
| - st.equal( |
55 |
| - isElement({ |
56 |
| - 'type': 'text' |
57 |
| - }, 'div'), |
58 |
| - false, |
59 |
| - 'should return `false` when without `element`' |
60 |
| - ); |
61 |
| - |
62 |
| - st.equal( |
63 |
| - isElement({ |
64 |
| - 'type': 'element' |
65 |
| - }, 'div'), |
66 |
| - false, |
67 |
| - 'should return `false` when with invalid `element`' |
68 |
| - ); |
69 |
| - |
70 |
| - st.equal( |
71 |
| - isElement({ |
72 |
| - 'type': 'element', |
73 |
| - 'tagName': 'strong' |
74 |
| - }, 'div'), |
75 |
| - false, |
76 |
| - 'should return `false` when without matching `element`' |
77 |
| - ); |
78 |
| - |
79 |
| - st.equal( |
80 |
| - isElement({ |
81 |
| - 'type': 'element', |
82 |
| - 'tagName': 'div' |
83 |
| - }, 'div'), |
84 |
| - true, |
85 |
| - 'should return `true` when with matching `element`' |
86 |
| - ); |
87 |
| - |
88 |
| - st.end(); |
89 |
| - }); |
90 |
| - |
91 |
| - t.test('isElement(node, tagNames)', function (st) { |
92 |
| - st.equal( |
93 |
| - isElement({ |
94 |
| - 'type': 'text' |
95 |
| - }, ['div']), |
96 |
| - false, |
97 |
| - 'should return `false` when without `element`' |
98 |
| - ); |
99 |
| - |
100 |
| - st.equal( |
101 |
| - isElement({ |
102 |
| - 'type': 'element' |
103 |
| - }, ['div']), |
104 |
| - false, |
105 |
| - 'should return `false` when with invalid `element`' |
106 |
| - ); |
107 |
| - |
108 |
| - st.equal( |
109 |
| - isElement({ |
110 |
| - 'type': 'element', |
111 |
| - 'tagName': 'strong' |
112 |
| - }, ['div']), |
113 |
| - false, |
114 |
| - 'should return `false` when without matching `element`' |
115 |
| - ); |
116 |
| - |
117 |
| - st.equal( |
118 |
| - isElement({ |
119 |
| - 'type': 'element', |
120 |
| - 'tagName': 'div' |
121 |
| - }, ['div', 'strong', 'em']), |
122 |
| - true, |
123 |
| - 'should return `true` when with matching `element` (#1)' |
124 |
| - ); |
125 |
| - |
126 |
| - st.equal( |
127 |
| - isElement({ |
128 |
| - 'type': 'element', |
129 |
| - 'tagName': 'em' |
130 |
| - }, ['div', 'strong', 'em']), |
131 |
| - true, |
132 |
| - 'should return `true` when with matching `element` (#2)' |
133 |
| - ); |
134 |
| - |
135 |
| - st.end(); |
136 |
| - }); |
137 |
| - |
138 |
| - t.end(); |
| 61 | + st.equal( |
| 62 | + isElement({type: 'element', tagName: 'div'}, 'div'), |
| 63 | + true, |
| 64 | + 'should return `true` when with matching `element`' |
| 65 | + ); |
| 66 | + |
| 67 | + st.end(); |
| 68 | + }); |
| 69 | + |
| 70 | + t.test('isElement(node, tagNames)', function (st) { |
| 71 | + st.equal( |
| 72 | + isElement({type: 'text'}, ['div']), |
| 73 | + false, |
| 74 | + 'should return `false` when without `element`' |
| 75 | + ); |
| 76 | + |
| 77 | + st.equal( |
| 78 | + isElement({type: 'element'}, ['div']), |
| 79 | + false, |
| 80 | + 'should return `false` when with invalid `element`' |
| 81 | + ); |
| 82 | + |
| 83 | + st.equal( |
| 84 | + isElement({type: 'element', tagName: 'strong'}, ['div']), |
| 85 | + false, |
| 86 | + 'should return `false` when without matching `element`' |
| 87 | + ); |
| 88 | + |
| 89 | + st.equal( |
| 90 | + isElement({type: 'element', tagName: 'div'}, ['div', 'strong', 'em']), |
| 91 | + true, |
| 92 | + 'should return `true` when with matching `element` (#1)' |
| 93 | + ); |
| 94 | + |
| 95 | + st.equal( |
| 96 | + isElement({type: 'element', tagName: 'em'}, ['div', 'strong', 'em']), |
| 97 | + true, |
| 98 | + 'should return `true` when with matching `element` (#2)' |
| 99 | + ); |
| 100 | + |
| 101 | + st.end(); |
| 102 | + }); |
| 103 | + |
| 104 | + t.end(); |
139 | 105 | });
|
0 commit comments