@cypress/unique-selector 0.4.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/getData.js +7 -23
- package/lib/getName.js +19 -0
- package/lib/index.js +34 -56
- package/lib/isUnique.js +6 -2
- package/package.json +8 -11
- package/.babelrc +0 -3
- package/.eslintrc +0 -42
- package/.history/package-lock_20211116100405.json +0 -7884
- package/.history/package-lock_20211116101347.json +0 -7884
- package/.history/package_20180226102655.json +0 -62
- package/.history/package_20211018091805.json +0 -62
- package/.history/package_20211018091928.json +0 -62
- package/.history/package_20211116101343.json +0 -62
- package/.history/src/getData_20211116100405.js +0 -24
- package/.history/src/getData_20211116100500.js +0 -24
- package/.history/src/getData_20211116100511.js +0 -24
- package/.history/src/getData_20211116100803.js +0 -25
- package/.history/src/getData_20211116100925.js +0 -25
- package/.history/src/getData_20211116101054.js +0 -25
- package/.history/src/getData_20211116101058.js +0 -25
- package/.history/src/getData_20211116101234.js +0 -26
- package/.history/src/getData_20211116101243.js +0 -28
- package/.history/src/getData_20211116101301.js +0 -29
- package/.history/test/unique-selector_20180226102601.js +0 -131
- package/.history/test/unique-selector_20211018092001.js +0 -131
- package/.history/test/unique-selector_20211018092018.js +0 -131
- package/.history/test/unique-selector_20211018092209.js +0 -132
- package/.history/test/unique-selector_20211018092230.js +0 -132
- package/.history/test/unique-selector_20211018092245.js +0 -130
- package/.travis.yml +0 -11
- package/component.json +0 -12
- package/src/getAttributes.js +0 -20
- package/src/getClasses.js +0 -38
- package/src/getCombinations.js +0 -44
- package/src/getData.js +0 -29
- package/src/getID.js +0 -17
- package/src/getNthChild.js +0 -33
- package/src/getParents.js +0 -19
- package/src/getTag.js +0 -9
- package/src/index.js +0 -197
- package/src/isElement.js +0 -17
- package/src/isUnique.js +0 -12
- package/static/bundle.js +0 -5
- package/test/index.html +0 -0
- package/test/unique-selector.js +0 -146
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
const jsdom = require( 'mocha-jsdom' );
|
|
2
|
-
const expect = require( 'chai' ).expect;
|
|
3
|
-
const unique = require('../src');
|
|
4
|
-
|
|
5
|
-
const $ = require( 'jquery' )( require( 'jsdom' ).jsdom().defaultView );
|
|
6
|
-
|
|
7
|
-
describe( 'Unique Selector Tests', () =>
|
|
8
|
-
{
|
|
9
|
-
jsdom( { skipWindowCheck : true } );
|
|
10
|
-
|
|
11
|
-
it( 'ID', () =>
|
|
12
|
-
{
|
|
13
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
14
|
-
$( 'body' ).append( '<div id="so" class="test3"></div>' );
|
|
15
|
-
const findNode = $( 'body' ).find( '.test3' ).get( 0 );
|
|
16
|
-
const uniqueSelector = unique( findNode );
|
|
17
|
-
expect( uniqueSelector ).to.equal( '#so' );
|
|
18
|
-
} );
|
|
19
|
-
|
|
20
|
-
it( 'ID that needs escaping', () =>
|
|
21
|
-
{
|
|
22
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
23
|
-
$( 'body' ).append( '<div id="123" class="test3"></div>' );
|
|
24
|
-
const findNode = $( 'body' ).find( '.test3' ).get( 0 );
|
|
25
|
-
const uniqueSelector = unique( findNode );
|
|
26
|
-
expect( uniqueSelector ).to.equal( '#\\31 23' );
|
|
27
|
-
} );
|
|
28
|
-
|
|
29
|
-
it( 'Class', () =>
|
|
30
|
-
{
|
|
31
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
32
|
-
$( 'body' ).append( '<div class="test2"></div>' );
|
|
33
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
34
|
-
const uniqueSelector = unique( findNode );
|
|
35
|
-
expect( uniqueSelector ).to.equal( '.test2' );
|
|
36
|
-
} );
|
|
37
|
-
|
|
38
|
-
it( 'Class that needs escaping', () =>
|
|
39
|
-
{
|
|
40
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
41
|
-
$( 'body' ).append( '<div class="@test test2"></div>' );
|
|
42
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
43
|
-
const uniqueSelector = unique( findNode );
|
|
44
|
-
expect( uniqueSelector ).to.equal( '.\\@test' );
|
|
45
|
-
} );
|
|
46
|
-
|
|
47
|
-
it( 'Classes', () =>
|
|
48
|
-
{
|
|
49
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
50
|
-
$( 'body' ).append( '<div class="test2"></div><div class="test2"></div>' );
|
|
51
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
52
|
-
const uniqueSelector = unique( findNode );
|
|
53
|
-
expect( uniqueSelector ).to.equal( 'body > :nth-child(1)' );
|
|
54
|
-
} );
|
|
55
|
-
|
|
56
|
-
it( 'Classes', () =>
|
|
57
|
-
{
|
|
58
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
59
|
-
$( 'body' ).append( '<div class="test2 ca cb cc cd cx"></div><div class="test2 ca cb cc cd ce"></div><div class="test2 ca cb cc cd ce"></div><div class="test2 ca cb cd ce cf cx"></div>' );
|
|
60
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
61
|
-
const uniqueSelector = unique( findNode );
|
|
62
|
-
expect( uniqueSelector ).to.equal( '.cc.cx' );
|
|
63
|
-
} );
|
|
64
|
-
|
|
65
|
-
it( 'Classes with newline', () =>
|
|
66
|
-
{
|
|
67
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
68
|
-
$( 'body' ).append( '<div class="test2\n ca\n cb\n cc\n cd\n cx"></div><div class="test2\n ca\n cb\n cc\n cd\n ce"></div><div class="test2\n ca\n cb\n cc\n cd\n ce"></div><div class="test2\n ca\n cb\n cd\n ce\n cf\n cx"></div>' );
|
|
69
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
70
|
-
const uniqueSelector = unique( findNode );
|
|
71
|
-
expect( uniqueSelector ).to.equal( '.cc.cx' );
|
|
72
|
-
} );
|
|
73
|
-
|
|
74
|
-
it( 'Tag', () =>
|
|
75
|
-
{
|
|
76
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
77
|
-
$( 'body' ).append( '<div class="test2"><span></span></div><div class="test2"></div>' );
|
|
78
|
-
const findNode = $( '.test2' ).find( 'span' ).get( 0 );
|
|
79
|
-
const uniqueSelector = unique( findNode );
|
|
80
|
-
expect( uniqueSelector ).to.equal( 'span' );
|
|
81
|
-
} );
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
it( 'Tag', () =>
|
|
85
|
-
{
|
|
86
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
87
|
-
$( 'body' ).append( '<div class="test5"><span></span></div><div class="test5"><span></span></div>' );
|
|
88
|
-
const findNode = $( '.test5' ).find( 'span' ).get( 0 );
|
|
89
|
-
const uniqueSelector = unique( findNode );
|
|
90
|
-
expect( uniqueSelector ).to.equal( ':nth-child(1) > span' );
|
|
91
|
-
} );
|
|
92
|
-
|
|
93
|
-
it( 'Tag', () =>
|
|
94
|
-
{
|
|
95
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
96
|
-
$( 'body' ).append( '<div class="test5"><span><ul><li><a></a></li></ul></span></div><div class="test5"><span></span></div>' );
|
|
97
|
-
const findNode = $( '.test5' ).find( 'a' ).get( 0 );
|
|
98
|
-
const uniqueSelector = unique( findNode );
|
|
99
|
-
expect( uniqueSelector ).to.equal( 'a' );
|
|
100
|
-
} );
|
|
101
|
-
|
|
102
|
-
it( 'Attributes', () =>
|
|
103
|
-
{
|
|
104
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
105
|
-
$( 'body' ).append( '<div class="test5" test="5"></div>' );
|
|
106
|
-
const findNode = $( '.test5' ).get( 0 );
|
|
107
|
-
const uniqueSelector = unique( findNode, { selectorTypes : ['attributes'] });
|
|
108
|
-
expect( uniqueSelector ).to.equal( '[test="5"]' );
|
|
109
|
-
} );
|
|
110
|
-
|
|
111
|
-
it( 'data-foo', () =>
|
|
112
|
-
{
|
|
113
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
114
|
-
$( 'body' ).append( '<div data-foo="so" class="test6"></div>' );
|
|
115
|
-
const findNode = $( 'body' ).find( '.test6' ).get( 0 );
|
|
116
|
-
findNode.dataset = { foo : 'so' }
|
|
117
|
-
const uniqueSelector = unique( findNode, { selectorTypes : ['data-foo'] } );
|
|
118
|
-
expect( uniqueSelector ).to.equal( '[data-foo=so]' );
|
|
119
|
-
} );
|
|
120
|
-
|
|
121
|
-
it( 'data-foo that needs escaping', () =>
|
|
122
|
-
{
|
|
123
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
124
|
-
$( 'body' ).append( '<div data-foo="123" class="test7"></div>' );
|
|
125
|
-
const findNode = $( 'body' ).find( '.test7' ).get( 0 );
|
|
126
|
-
findNode.dataset = { foo : '123' }
|
|
127
|
-
const uniqueSelector = unique( findNode, { selectorTypes : ['data-foo'] } );
|
|
128
|
-
expect( uniqueSelector ).to.equal( '[data-foo=\\31 23]' );
|
|
129
|
-
} );
|
|
130
|
-
|
|
131
|
-
} );
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
const jsdom = require( 'mocha-jsdom' );
|
|
2
|
-
const expect = require( 'chai' ).expect;
|
|
3
|
-
const unique = require('../lib');
|
|
4
|
-
|
|
5
|
-
const $ = require( 'jquery' )( require( 'jsdom' ).jsdom().defaultView );
|
|
6
|
-
|
|
7
|
-
describe( 'Unique Selector Tests', () =>
|
|
8
|
-
{
|
|
9
|
-
jsdom( { skipWindowCheck : true } );
|
|
10
|
-
|
|
11
|
-
it( 'ID', () =>
|
|
12
|
-
{
|
|
13
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
14
|
-
$( 'body' ).append( '<div id="so" class="test3"></div>' );
|
|
15
|
-
const findNode = $( 'body' ).find( '.test3' ).get( 0 );
|
|
16
|
-
const uniqueSelector = unique( findNode );
|
|
17
|
-
expect( uniqueSelector ).to.equal( '#so' );
|
|
18
|
-
} );
|
|
19
|
-
|
|
20
|
-
it( 'ID that needs escaping', () =>
|
|
21
|
-
{
|
|
22
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
23
|
-
$( 'body' ).append( '<div id="123" class="test3"></div>' );
|
|
24
|
-
const findNode = $( 'body' ).find( '.test3' ).get( 0 );
|
|
25
|
-
const uniqueSelector = unique( findNode );
|
|
26
|
-
expect( uniqueSelector ).to.equal( '#\\31 23' );
|
|
27
|
-
} );
|
|
28
|
-
|
|
29
|
-
it( 'Class', () =>
|
|
30
|
-
{
|
|
31
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
32
|
-
$( 'body' ).append( '<div class="test2"></div>' );
|
|
33
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
34
|
-
const uniqueSelector = unique( findNode );
|
|
35
|
-
expect( uniqueSelector ).to.equal( '.test2' );
|
|
36
|
-
} );
|
|
37
|
-
|
|
38
|
-
it( 'Class that needs escaping', () =>
|
|
39
|
-
{
|
|
40
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
41
|
-
$( 'body' ).append( '<div class="@test test2"></div>' );
|
|
42
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
43
|
-
const uniqueSelector = unique( findNode );
|
|
44
|
-
expect( uniqueSelector ).to.equal( '.\\@test' );
|
|
45
|
-
} );
|
|
46
|
-
|
|
47
|
-
it( 'Classes', () =>
|
|
48
|
-
{
|
|
49
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
50
|
-
$( 'body' ).append( '<div class="test2"></div><div class="test2"></div>' );
|
|
51
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
52
|
-
const uniqueSelector = unique( findNode );
|
|
53
|
-
expect( uniqueSelector ).to.equal( 'body > :nth-child(1)' );
|
|
54
|
-
} );
|
|
55
|
-
|
|
56
|
-
it( 'Classes', () =>
|
|
57
|
-
{
|
|
58
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
59
|
-
$( 'body' ).append( '<div class="test2 ca cb cc cd cx"></div><div class="test2 ca cb cc cd ce"></div><div class="test2 ca cb cc cd ce"></div><div class="test2 ca cb cd ce cf cx"></div>' );
|
|
60
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
61
|
-
const uniqueSelector = unique( findNode );
|
|
62
|
-
expect( uniqueSelector ).to.equal( '.cc.cx' );
|
|
63
|
-
} );
|
|
64
|
-
|
|
65
|
-
it( 'Classes with newline', () =>
|
|
66
|
-
{
|
|
67
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
68
|
-
$( 'body' ).append( '<div class="test2\n ca\n cb\n cc\n cd\n cx"></div><div class="test2\n ca\n cb\n cc\n cd\n ce"></div><div class="test2\n ca\n cb\n cc\n cd\n ce"></div><div class="test2\n ca\n cb\n cd\n ce\n cf\n cx"></div>' );
|
|
69
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
70
|
-
const uniqueSelector = unique( findNode );
|
|
71
|
-
expect( uniqueSelector ).to.equal( '.cc.cx' );
|
|
72
|
-
} );
|
|
73
|
-
|
|
74
|
-
it( 'Tag', () =>
|
|
75
|
-
{
|
|
76
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
77
|
-
$( 'body' ).append( '<div class="test2"><span></span></div><div class="test2"></div>' );
|
|
78
|
-
const findNode = $( '.test2' ).find( 'span' ).get( 0 );
|
|
79
|
-
const uniqueSelector = unique( findNode );
|
|
80
|
-
expect( uniqueSelector ).to.equal( 'span' );
|
|
81
|
-
} );
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
it( 'Tag', () =>
|
|
85
|
-
{
|
|
86
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
87
|
-
$( 'body' ).append( '<div class="test5"><span></span></div><div class="test5"><span></span></div>' );
|
|
88
|
-
const findNode = $( '.test5' ).find( 'span' ).get( 0 );
|
|
89
|
-
const uniqueSelector = unique( findNode );
|
|
90
|
-
expect( uniqueSelector ).to.equal( ':nth-child(1) > span' );
|
|
91
|
-
} );
|
|
92
|
-
|
|
93
|
-
it( 'Tag', () =>
|
|
94
|
-
{
|
|
95
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
96
|
-
$( 'body' ).append( '<div class="test5"><span><ul><li><a></a></li></ul></span></div><div class="test5"><span></span></div>' );
|
|
97
|
-
const findNode = $( '.test5' ).find( 'a' ).get( 0 );
|
|
98
|
-
const uniqueSelector = unique( findNode );
|
|
99
|
-
expect( uniqueSelector ).to.equal( 'a' );
|
|
100
|
-
} );
|
|
101
|
-
|
|
102
|
-
it( 'Attributes', () =>
|
|
103
|
-
{
|
|
104
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
105
|
-
$( 'body' ).append( '<div class="test5" test="5"></div>' );
|
|
106
|
-
const findNode = $( '.test5' ).get( 0 );
|
|
107
|
-
const uniqueSelector = unique( findNode, { selectorTypes : ['attributes'] });
|
|
108
|
-
expect( uniqueSelector ).to.equal( '[test="5"]' );
|
|
109
|
-
} );
|
|
110
|
-
|
|
111
|
-
it( 'data-foo', () =>
|
|
112
|
-
{
|
|
113
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
114
|
-
$( 'body' ).append( '<div data-foo="so" class="test6"></div>' );
|
|
115
|
-
const findNode = $( 'body' ).find( '.test6' ).get( 0 );
|
|
116
|
-
findNode.dataset = { foo : 'so' }
|
|
117
|
-
const uniqueSelector = unique( findNode, { selectorTypes : ['data-foo'] } );
|
|
118
|
-
expect( uniqueSelector ).to.equal( '[data-foo=so]' );
|
|
119
|
-
} );
|
|
120
|
-
|
|
121
|
-
it( 'data-foo that needs escaping', () =>
|
|
122
|
-
{
|
|
123
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
124
|
-
$( 'body' ).append( '<div data-foo="123" class="test7"></div>' );
|
|
125
|
-
const findNode = $( 'body' ).find( '.test7' ).get( 0 );
|
|
126
|
-
findNode.dataset = { foo : '123' }
|
|
127
|
-
const uniqueSelector = unique( findNode, { selectorTypes : ['data-foo'] } );
|
|
128
|
-
expect( uniqueSelector ).to.equal( '[data-foo=\\31 23]' );
|
|
129
|
-
} );
|
|
130
|
-
|
|
131
|
-
} );
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
// const jsdom = require( 'mocha-jsdom' );
|
|
2
|
-
const expect = require( 'chai' ).expect;
|
|
3
|
-
const JSDOM = require('jsdom').JSDOM;
|
|
4
|
-
const unique = require('../lib');
|
|
5
|
-
|
|
6
|
-
const $ = require( 'jquery' )( (new JSDOM()).window );
|
|
7
|
-
|
|
8
|
-
describe( 'Unique Selector Tests', () =>
|
|
9
|
-
{
|
|
10
|
-
// jsdom( { skipWindowCheck : true } );
|
|
11
|
-
|
|
12
|
-
it( 'ID', () =>
|
|
13
|
-
{
|
|
14
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
15
|
-
$( 'body' ).append( '<div id="so" class="test3"></div>' );
|
|
16
|
-
const findNode = $( 'body' ).find( '.test3' ).get( 0 );
|
|
17
|
-
const uniqueSelector = unique( findNode );
|
|
18
|
-
expect( uniqueSelector ).to.equal( '#so' );
|
|
19
|
-
} );
|
|
20
|
-
|
|
21
|
-
it( 'ID that needs escaping', () =>
|
|
22
|
-
{
|
|
23
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
24
|
-
$( 'body' ).append( '<div id="123" class="test3"></div>' );
|
|
25
|
-
const findNode = $( 'body' ).find( '.test3' ).get( 0 );
|
|
26
|
-
const uniqueSelector = unique( findNode );
|
|
27
|
-
expect( uniqueSelector ).to.equal( '#\\31 23' );
|
|
28
|
-
} );
|
|
29
|
-
|
|
30
|
-
it( 'Class', () =>
|
|
31
|
-
{
|
|
32
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
33
|
-
$( 'body' ).append( '<div class="test2"></div>' );
|
|
34
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
35
|
-
const uniqueSelector = unique( findNode );
|
|
36
|
-
expect( uniqueSelector ).to.equal( '.test2' );
|
|
37
|
-
} );
|
|
38
|
-
|
|
39
|
-
it( 'Class that needs escaping', () =>
|
|
40
|
-
{
|
|
41
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
42
|
-
$( 'body' ).append( '<div class="@test test2"></div>' );
|
|
43
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
44
|
-
const uniqueSelector = unique( findNode );
|
|
45
|
-
expect( uniqueSelector ).to.equal( '.\\@test' );
|
|
46
|
-
} );
|
|
47
|
-
|
|
48
|
-
it( 'Classes', () =>
|
|
49
|
-
{
|
|
50
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
51
|
-
$( 'body' ).append( '<div class="test2"></div><div class="test2"></div>' );
|
|
52
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
53
|
-
const uniqueSelector = unique( findNode );
|
|
54
|
-
expect( uniqueSelector ).to.equal( 'body > :nth-child(1)' );
|
|
55
|
-
} );
|
|
56
|
-
|
|
57
|
-
it( 'Classes', () =>
|
|
58
|
-
{
|
|
59
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
60
|
-
$( 'body' ).append( '<div class="test2 ca cb cc cd cx"></div><div class="test2 ca cb cc cd ce"></div><div class="test2 ca cb cc cd ce"></div><div class="test2 ca cb cd ce cf cx"></div>' );
|
|
61
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
62
|
-
const uniqueSelector = unique( findNode );
|
|
63
|
-
expect( uniqueSelector ).to.equal( '.cc.cx' );
|
|
64
|
-
} );
|
|
65
|
-
|
|
66
|
-
it( 'Classes with newline', () =>
|
|
67
|
-
{
|
|
68
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
69
|
-
$( 'body' ).append( '<div class="test2\n ca\n cb\n cc\n cd\n cx"></div><div class="test2\n ca\n cb\n cc\n cd\n ce"></div><div class="test2\n ca\n cb\n cc\n cd\n ce"></div><div class="test2\n ca\n cb\n cd\n ce\n cf\n cx"></div>' );
|
|
70
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
71
|
-
const uniqueSelector = unique( findNode );
|
|
72
|
-
expect( uniqueSelector ).to.equal( '.cc.cx' );
|
|
73
|
-
} );
|
|
74
|
-
|
|
75
|
-
it( 'Tag', () =>
|
|
76
|
-
{
|
|
77
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
78
|
-
$( 'body' ).append( '<div class="test2"><span></span></div><div class="test2"></div>' );
|
|
79
|
-
const findNode = $( '.test2' ).find( 'span' ).get( 0 );
|
|
80
|
-
const uniqueSelector = unique( findNode );
|
|
81
|
-
expect( uniqueSelector ).to.equal( 'span' );
|
|
82
|
-
} );
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
it( 'Tag', () =>
|
|
86
|
-
{
|
|
87
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
88
|
-
$( 'body' ).append( '<div class="test5"><span></span></div><div class="test5"><span></span></div>' );
|
|
89
|
-
const findNode = $( '.test5' ).find( 'span' ).get( 0 );
|
|
90
|
-
const uniqueSelector = unique( findNode );
|
|
91
|
-
expect( uniqueSelector ).to.equal( ':nth-child(1) > span' );
|
|
92
|
-
} );
|
|
93
|
-
|
|
94
|
-
it( 'Tag', () =>
|
|
95
|
-
{
|
|
96
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
97
|
-
$( 'body' ).append( '<div class="test5"><span><ul><li><a></a></li></ul></span></div><div class="test5"><span></span></div>' );
|
|
98
|
-
const findNode = $( '.test5' ).find( 'a' ).get( 0 );
|
|
99
|
-
const uniqueSelector = unique( findNode );
|
|
100
|
-
expect( uniqueSelector ).to.equal( 'a' );
|
|
101
|
-
} );
|
|
102
|
-
|
|
103
|
-
it( 'Attributes', () =>
|
|
104
|
-
{
|
|
105
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
106
|
-
$( 'body' ).append( '<div class="test5" test="5"></div>' );
|
|
107
|
-
const findNode = $( '.test5' ).get( 0 );
|
|
108
|
-
const uniqueSelector = unique( findNode, { selectorTypes : ['attributes'] });
|
|
109
|
-
expect( uniqueSelector ).to.equal( '[test="5"]' );
|
|
110
|
-
} );
|
|
111
|
-
|
|
112
|
-
it( 'data-foo', () =>
|
|
113
|
-
{
|
|
114
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
115
|
-
$( 'body' ).append( '<div data-foo="so" class="test6"></div>' );
|
|
116
|
-
const findNode = $( 'body' ).find( '.test6' ).get( 0 );
|
|
117
|
-
findNode.dataset = { foo : 'so' }
|
|
118
|
-
const uniqueSelector = unique( findNode, { selectorTypes : ['data-foo'] } );
|
|
119
|
-
expect( uniqueSelector ).to.equal( '[data-foo=so]' );
|
|
120
|
-
} );
|
|
121
|
-
|
|
122
|
-
it( 'data-foo that needs escaping', () =>
|
|
123
|
-
{
|
|
124
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
125
|
-
$( 'body' ).append( '<div data-foo="123" class="test7"></div>' );
|
|
126
|
-
const findNode = $( 'body' ).find( '.test7' ).get( 0 );
|
|
127
|
-
findNode.dataset = { foo : '123' }
|
|
128
|
-
const uniqueSelector = unique( findNode, { selectorTypes : ['data-foo'] } );
|
|
129
|
-
expect( uniqueSelector ).to.equal( '[data-foo=\\31 23]' );
|
|
130
|
-
} );
|
|
131
|
-
|
|
132
|
-
} );
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
// const jsdom = require( 'mocha-jsdom' );
|
|
2
|
-
const expect = require( 'chai' ).expect;
|
|
3
|
-
const JSDOM = require('jsdom').JSDOM;
|
|
4
|
-
const unique = require('../lib').default;
|
|
5
|
-
|
|
6
|
-
const $ = require( 'jquery' )( (new JSDOM()).window );
|
|
7
|
-
|
|
8
|
-
describe( 'Unique Selector Tests', () =>
|
|
9
|
-
{
|
|
10
|
-
// jsdom( { skipWindowCheck : true } );
|
|
11
|
-
|
|
12
|
-
it( 'ID', () =>
|
|
13
|
-
{
|
|
14
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
15
|
-
$( 'body' ).append( '<div id="so" class="test3"></div>' );
|
|
16
|
-
const findNode = $( 'body' ).find( '.test3' ).get( 0 );
|
|
17
|
-
const uniqueSelector = unique( findNode );
|
|
18
|
-
expect( uniqueSelector ).to.equal( '#so' );
|
|
19
|
-
} );
|
|
20
|
-
|
|
21
|
-
it( 'ID that needs escaping', () =>
|
|
22
|
-
{
|
|
23
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
24
|
-
$( 'body' ).append( '<div id="123" class="test3"></div>' );
|
|
25
|
-
const findNode = $( 'body' ).find( '.test3' ).get( 0 );
|
|
26
|
-
const uniqueSelector = unique( findNode );
|
|
27
|
-
expect( uniqueSelector ).to.equal( '#\\31 23' );
|
|
28
|
-
} );
|
|
29
|
-
|
|
30
|
-
it( 'Class', () =>
|
|
31
|
-
{
|
|
32
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
33
|
-
$( 'body' ).append( '<div class="test2"></div>' );
|
|
34
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
35
|
-
const uniqueSelector = unique( findNode );
|
|
36
|
-
expect( uniqueSelector ).to.equal( '.test2' );
|
|
37
|
-
} );
|
|
38
|
-
|
|
39
|
-
it( 'Class that needs escaping', () =>
|
|
40
|
-
{
|
|
41
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
42
|
-
$( 'body' ).append( '<div class="@test test2"></div>' );
|
|
43
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
44
|
-
const uniqueSelector = unique( findNode );
|
|
45
|
-
expect( uniqueSelector ).to.equal( '.\\@test' );
|
|
46
|
-
} );
|
|
47
|
-
|
|
48
|
-
it( 'Classes', () =>
|
|
49
|
-
{
|
|
50
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
51
|
-
$( 'body' ).append( '<div class="test2"></div><div class="test2"></div>' );
|
|
52
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
53
|
-
const uniqueSelector = unique( findNode );
|
|
54
|
-
expect( uniqueSelector ).to.equal( 'body > :nth-child(1)' );
|
|
55
|
-
} );
|
|
56
|
-
|
|
57
|
-
it( 'Classes', () =>
|
|
58
|
-
{
|
|
59
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
60
|
-
$( 'body' ).append( '<div class="test2 ca cb cc cd cx"></div><div class="test2 ca cb cc cd ce"></div><div class="test2 ca cb cc cd ce"></div><div class="test2 ca cb cd ce cf cx"></div>' );
|
|
61
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
62
|
-
const uniqueSelector = unique( findNode );
|
|
63
|
-
expect( uniqueSelector ).to.equal( '.cc.cx' );
|
|
64
|
-
} );
|
|
65
|
-
|
|
66
|
-
it( 'Classes with newline', () =>
|
|
67
|
-
{
|
|
68
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
69
|
-
$( 'body' ).append( '<div class="test2\n ca\n cb\n cc\n cd\n cx"></div><div class="test2\n ca\n cb\n cc\n cd\n ce"></div><div class="test2\n ca\n cb\n cc\n cd\n ce"></div><div class="test2\n ca\n cb\n cd\n ce\n cf\n cx"></div>' );
|
|
70
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
71
|
-
const uniqueSelector = unique( findNode );
|
|
72
|
-
expect( uniqueSelector ).to.equal( '.cc.cx' );
|
|
73
|
-
} );
|
|
74
|
-
|
|
75
|
-
it( 'Tag', () =>
|
|
76
|
-
{
|
|
77
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
78
|
-
$( 'body' ).append( '<div class="test2"><span></span></div><div class="test2"></div>' );
|
|
79
|
-
const findNode = $( '.test2' ).find( 'span' ).get( 0 );
|
|
80
|
-
const uniqueSelector = unique( findNode );
|
|
81
|
-
expect( uniqueSelector ).to.equal( 'span' );
|
|
82
|
-
} );
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
it( 'Tag', () =>
|
|
86
|
-
{
|
|
87
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
88
|
-
$( 'body' ).append( '<div class="test5"><span></span></div><div class="test5"><span></span></div>' );
|
|
89
|
-
const findNode = $( '.test5' ).find( 'span' ).get( 0 );
|
|
90
|
-
const uniqueSelector = unique( findNode );
|
|
91
|
-
expect( uniqueSelector ).to.equal( ':nth-child(1) > span' );
|
|
92
|
-
} );
|
|
93
|
-
|
|
94
|
-
it( 'Tag', () =>
|
|
95
|
-
{
|
|
96
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
97
|
-
$( 'body' ).append( '<div class="test5"><span><ul><li><a></a></li></ul></span></div><div class="test5"><span></span></div>' );
|
|
98
|
-
const findNode = $( '.test5' ).find( 'a' ).get( 0 );
|
|
99
|
-
const uniqueSelector = unique( findNode );
|
|
100
|
-
expect( uniqueSelector ).to.equal( 'a' );
|
|
101
|
-
} );
|
|
102
|
-
|
|
103
|
-
it( 'Attributes', () =>
|
|
104
|
-
{
|
|
105
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
106
|
-
$( 'body' ).append( '<div class="test5" test="5"></div>' );
|
|
107
|
-
const findNode = $( '.test5' ).get( 0 );
|
|
108
|
-
const uniqueSelector = unique( findNode, { selectorTypes : ['attributes'] });
|
|
109
|
-
expect( uniqueSelector ).to.equal( '[test="5"]' );
|
|
110
|
-
} );
|
|
111
|
-
|
|
112
|
-
it( 'data-foo', () =>
|
|
113
|
-
{
|
|
114
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
115
|
-
$( 'body' ).append( '<div data-foo="so" class="test6"></div>' );
|
|
116
|
-
const findNode = $( 'body' ).find( '.test6' ).get( 0 );
|
|
117
|
-
findNode.dataset = { foo : 'so' }
|
|
118
|
-
const uniqueSelector = unique( findNode, { selectorTypes : ['data-foo'] } );
|
|
119
|
-
expect( uniqueSelector ).to.equal( '[data-foo=so]' );
|
|
120
|
-
} );
|
|
121
|
-
|
|
122
|
-
it( 'data-foo that needs escaping', () =>
|
|
123
|
-
{
|
|
124
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
125
|
-
$( 'body' ).append( '<div data-foo="123" class="test7"></div>' );
|
|
126
|
-
const findNode = $( 'body' ).find( '.test7' ).get( 0 );
|
|
127
|
-
findNode.dataset = { foo : '123' }
|
|
128
|
-
const uniqueSelector = unique( findNode, { selectorTypes : ['data-foo'] } );
|
|
129
|
-
expect( uniqueSelector ).to.equal( '[data-foo=\\31 23]' );
|
|
130
|
-
} );
|
|
131
|
-
|
|
132
|
-
} );
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
const expect = require( 'chai' ).expect;
|
|
2
|
-
const JSDOM = require('jsdom').JSDOM;
|
|
3
|
-
const unique = require('../lib').default;
|
|
4
|
-
|
|
5
|
-
const $ = require( 'jquery' )( (new JSDOM()).window );
|
|
6
|
-
|
|
7
|
-
describe( 'Unique Selector Tests', () =>
|
|
8
|
-
{
|
|
9
|
-
|
|
10
|
-
it( 'ID', () =>
|
|
11
|
-
{
|
|
12
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
13
|
-
$( 'body' ).append( '<div id="so" class="test3"></div>' );
|
|
14
|
-
const findNode = $( 'body' ).find( '.test3' ).get( 0 );
|
|
15
|
-
const uniqueSelector = unique( findNode );
|
|
16
|
-
expect( uniqueSelector ).to.equal( '#so' );
|
|
17
|
-
} );
|
|
18
|
-
|
|
19
|
-
it( 'ID that needs escaping', () =>
|
|
20
|
-
{
|
|
21
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
22
|
-
$( 'body' ).append( '<div id="123" class="test3"></div>' );
|
|
23
|
-
const findNode = $( 'body' ).find( '.test3' ).get( 0 );
|
|
24
|
-
const uniqueSelector = unique( findNode );
|
|
25
|
-
expect( uniqueSelector ).to.equal( '#\\31 23' );
|
|
26
|
-
} );
|
|
27
|
-
|
|
28
|
-
it( 'Class', () =>
|
|
29
|
-
{
|
|
30
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
31
|
-
$( 'body' ).append( '<div class="test2"></div>' );
|
|
32
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
33
|
-
const uniqueSelector = unique( findNode );
|
|
34
|
-
expect( uniqueSelector ).to.equal( '.test2' );
|
|
35
|
-
} );
|
|
36
|
-
|
|
37
|
-
it( 'Class that needs escaping', () =>
|
|
38
|
-
{
|
|
39
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
40
|
-
$( 'body' ).append( '<div class="@test test2"></div>' );
|
|
41
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
42
|
-
const uniqueSelector = unique( findNode );
|
|
43
|
-
expect( uniqueSelector ).to.equal( '.\\@test' );
|
|
44
|
-
} );
|
|
45
|
-
|
|
46
|
-
it( 'Classes', () =>
|
|
47
|
-
{
|
|
48
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
49
|
-
$( 'body' ).append( '<div class="test2"></div><div class="test2"></div>' );
|
|
50
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
51
|
-
const uniqueSelector = unique( findNode );
|
|
52
|
-
expect( uniqueSelector ).to.equal( 'body > :nth-child(1)' );
|
|
53
|
-
} );
|
|
54
|
-
|
|
55
|
-
it( 'Classes', () =>
|
|
56
|
-
{
|
|
57
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
58
|
-
$( 'body' ).append( '<div class="test2 ca cb cc cd cx"></div><div class="test2 ca cb cc cd ce"></div><div class="test2 ca cb cc cd ce"></div><div class="test2 ca cb cd ce cf cx"></div>' );
|
|
59
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
60
|
-
const uniqueSelector = unique( findNode );
|
|
61
|
-
expect( uniqueSelector ).to.equal( '.cc.cx' );
|
|
62
|
-
} );
|
|
63
|
-
|
|
64
|
-
it( 'Classes with newline', () =>
|
|
65
|
-
{
|
|
66
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
67
|
-
$( 'body' ).append( '<div class="test2\n ca\n cb\n cc\n cd\n cx"></div><div class="test2\n ca\n cb\n cc\n cd\n ce"></div><div class="test2\n ca\n cb\n cc\n cd\n ce"></div><div class="test2\n ca\n cb\n cd\n ce\n cf\n cx"></div>' );
|
|
68
|
-
const findNode = $( 'body' ).find( '.test2' ).get( 0 );
|
|
69
|
-
const uniqueSelector = unique( findNode );
|
|
70
|
-
expect( uniqueSelector ).to.equal( '.cc.cx' );
|
|
71
|
-
} );
|
|
72
|
-
|
|
73
|
-
it( 'Tag', () =>
|
|
74
|
-
{
|
|
75
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
76
|
-
$( 'body' ).append( '<div class="test2"><span></span></div><div class="test2"></div>' );
|
|
77
|
-
const findNode = $( '.test2' ).find( 'span' ).get( 0 );
|
|
78
|
-
const uniqueSelector = unique( findNode );
|
|
79
|
-
expect( uniqueSelector ).to.equal( 'span' );
|
|
80
|
-
} );
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
it( 'Tag', () =>
|
|
84
|
-
{
|
|
85
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
86
|
-
$( 'body' ).append( '<div class="test5"><span></span></div><div class="test5"><span></span></div>' );
|
|
87
|
-
const findNode = $( '.test5' ).find( 'span' ).get( 0 );
|
|
88
|
-
const uniqueSelector = unique( findNode );
|
|
89
|
-
expect( uniqueSelector ).to.equal( ':nth-child(1) > span' );
|
|
90
|
-
} );
|
|
91
|
-
|
|
92
|
-
it( 'Tag', () =>
|
|
93
|
-
{
|
|
94
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
95
|
-
$( 'body' ).append( '<div class="test5"><span><ul><li><a></a></li></ul></span></div><div class="test5"><span></span></div>' );
|
|
96
|
-
const findNode = $( '.test5' ).find( 'a' ).get( 0 );
|
|
97
|
-
const uniqueSelector = unique( findNode );
|
|
98
|
-
expect( uniqueSelector ).to.equal( 'a' );
|
|
99
|
-
} );
|
|
100
|
-
|
|
101
|
-
it( 'Attributes', () =>
|
|
102
|
-
{
|
|
103
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
104
|
-
$( 'body' ).append( '<div class="test5" test="5"></div>' );
|
|
105
|
-
const findNode = $( '.test5' ).get( 0 );
|
|
106
|
-
const uniqueSelector = unique( findNode, { selectorTypes : ['attributes'] });
|
|
107
|
-
expect( uniqueSelector ).to.equal( '[test="5"]' );
|
|
108
|
-
} );
|
|
109
|
-
|
|
110
|
-
it( 'data-foo', () =>
|
|
111
|
-
{
|
|
112
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
113
|
-
$( 'body' ).append( '<div data-foo="so" class="test6"></div>' );
|
|
114
|
-
const findNode = $( 'body' ).find( '.test6' ).get( 0 );
|
|
115
|
-
findNode.dataset = { foo : 'so' }
|
|
116
|
-
const uniqueSelector = unique( findNode, { selectorTypes : ['data-foo'] } );
|
|
117
|
-
expect( uniqueSelector ).to.equal( '[data-foo=so]' );
|
|
118
|
-
} );
|
|
119
|
-
|
|
120
|
-
it( 'data-foo that needs escaping', () =>
|
|
121
|
-
{
|
|
122
|
-
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
|
|
123
|
-
$( 'body' ).append( '<div data-foo="123" class="test7"></div>' );
|
|
124
|
-
const findNode = $( 'body' ).find( '.test7' ).get( 0 );
|
|
125
|
-
findNode.dataset = { foo : '123' }
|
|
126
|
-
const uniqueSelector = unique( findNode, { selectorTypes : ['data-foo'] } );
|
|
127
|
-
expect( uniqueSelector ).to.equal( '[data-foo=\\31 23]' );
|
|
128
|
-
} );
|
|
129
|
-
|
|
130
|
-
} );
|