File tree Expand file tree Collapse file tree 2 files changed +80
-1
lines changed Expand file tree Collapse file tree 2 files changed +80
-1
lines changed Original file line number Diff line number Diff line change 1
1
const whitespaceRegex = / [ \t \r \n \f ] / g;
2
2
3
+ class AbstractVirtualNode {
4
+ constructor ( ) {
5
+ this . children = [ ] ;
6
+ this . parent = null ;
7
+ }
8
+
9
+ get props ( ) {
10
+ throw new Error (
11
+ 'VirtualNode class must have a "props" object consisting ' +
12
+ 'of "nodeType" and "nodeName" properties'
13
+ ) ;
14
+ }
15
+
16
+ hasClass ( ) {
17
+ throw new Error ( 'VirtualNode class must have a "hasClass" function' ) ;
18
+ }
19
+
20
+ attr ( ) {
21
+ throw new Error ( 'VirtualNode class must have a "attr" function' ) ;
22
+ }
23
+
24
+ hasAttr ( ) {
25
+ throw new Error ( 'VirtualNode class must have a "hasAttr" function' ) ;
26
+ }
27
+ }
28
+
3
29
// class is unused in the file...
4
30
// eslint-disable-next-line no-unused-vars
5
- class VirtualNode {
31
+ class VirtualNode extends AbstractVirtualNode {
6
32
/**
7
33
* Wrap the real node and provide list of the flattened children
8
34
* @param {Node } node the node in question
9
35
* @param {VirtualNode } parent The parent VirtualNode
10
36
* @param {String } shadowId the ID of the shadow DOM to which this node belongs
11
37
*/
12
38
constructor ( node , parent , shadowId ) {
39
+ super ( ) ;
13
40
this . shadowId = shadowId ;
14
41
this . children = [ ] ;
15
42
this . actualNode = node ;
@@ -105,3 +132,5 @@ class VirtualNode {
105
132
return this . _cache . tabbableElements ;
106
133
}
107
134
}
135
+
136
+ axe . AbstractVirtualNode = AbstractVirtualNode ;
Original file line number Diff line number Diff line change @@ -7,6 +7,56 @@ describe('VirtualNode', function() {
7
7
node = document . createElement ( 'div' ) ;
8
8
} ) ;
9
9
10
+ describe ( 'AbstractVirtualNode' , function ( ) {
11
+ it ( 'should be a function' , function ( ) {
12
+ assert . isFunction ( axe . AbstractVirtualNode ) ;
13
+ } ) ;
14
+
15
+ it ( 'should throw an error when accessing props' , function ( ) {
16
+ function fn ( ) {
17
+ var abstractNode = new axe . AbstractVirtualNode ( ) ;
18
+ if ( abstractNode . props . nodeType === 1 ) {
19
+ return ;
20
+ }
21
+ }
22
+
23
+ assert . throws ( fn ) ;
24
+ } ) ;
25
+
26
+ it ( 'should throw an error when accessing hasClass' , function ( ) {
27
+ function fn ( ) {
28
+ var abstractNode = new axe . AbstractVirtualNode ( ) ;
29
+ if ( abstractNode . hasClass ( 'foo' ) ) {
30
+ return ;
31
+ }
32
+ }
33
+
34
+ assert . throws ( fn ) ;
35
+ } ) ;
36
+
37
+ it ( 'should throw an error when accessing attr' , function ( ) {
38
+ function fn ( ) {
39
+ var abstractNode = new axe . AbstractVirtualNode ( ) ;
40
+ if ( abstractNode . attr ( 'foo' ) === 'bar' ) {
41
+ return ;
42
+ }
43
+ }
44
+
45
+ assert . throws ( fn ) ;
46
+ } ) ;
47
+
48
+ it ( 'should throw an error when accessing hasAttr' , function ( ) {
49
+ function fn ( ) {
50
+ var abstractNode = new axe . AbstractVirtualNode ( ) ;
51
+ if ( abstractNode . hasAttr ( 'foo' ) ) {
52
+ return ;
53
+ }
54
+ }
55
+
56
+ assert . throws ( fn ) ;
57
+ } ) ;
58
+ } ) ;
59
+
10
60
it ( 'should be a function' , function ( ) {
11
61
assert . isFunction ( VirtualNode ) ;
12
62
} ) ;
You can’t perform that action at this time.
0 commit comments