@@ -105,27 +105,32 @@ function buildElementRoleList(elementRolesMap) {
105
105
}
106
106
107
107
function match ( element ) {
108
+ let { attributes = [ ] } = element
109
+
110
+ // https://github.com/testing-library/dom-testing-library/issues/814
111
+ const typeTextIndex = attributes . findIndex (
112
+ attribute =>
113
+ attribute . value &&
114
+ attribute . name === 'type' &&
115
+ attribute . value === 'text' ,
116
+ )
117
+
118
+ if ( typeTextIndex >= 0 ) {
119
+ // not using splice to not mutate the attributes array
120
+ attributes = [
121
+ ...attributes . slice ( 0 , typeTextIndex ) ,
122
+ ...attributes . slice ( typeTextIndex + 1 ) ,
123
+ ]
124
+ }
125
+
126
+ const selector = makeElementSelector ( { ...element , attributes} )
127
+
108
128
return node => {
109
- let { attributes = [ ] } = element
110
- // https://github.com/testing-library/dom-testing-library/issues/814
111
- const typeTextIndex = attributes . findIndex (
112
- attribute =>
113
- attribute . value &&
114
- attribute . name === 'type' &&
115
- attribute . value === 'text' ,
116
- )
117
- if ( typeTextIndex >= 0 ) {
118
- // not using splice to not mutate the attributes array
119
- attributes = [
120
- ...attributes . slice ( 0 , typeTextIndex ) ,
121
- ...attributes . slice ( typeTextIndex + 1 ) ,
122
- ]
123
- if ( node . type !== 'text' ) {
124
- return false
125
- }
129
+ if ( typeTextIndex >= 0 && node . type !== 'text' ) {
130
+ return false
126
131
}
127
132
128
- return node . matches ( makeElementSelector ( { ... element , attributes } ) )
133
+ return node . matches ( selector )
129
134
}
130
135
}
131
136
0 commit comments