MCPcopy Index your code
hub / github.com/react/react / matchSelector

Function matchSelector

packages/react-reconciler/src/ReactTestSelectors.js:145–209  ·  view source on GitHub ↗
(fiber: Fiber, selector: Selector)

Source from the content-addressed store, hash-verified

143}
144
145function matchSelector(fiber: Fiber, selector: Selector): boolean {
146 const tag = fiber.tag;
147 switch (selector.$$typeof) {
148 case COMPONENT_TYPE:
149 if (fiber.type === selector.value) {
150 return true;
151 }
152 break;
153 case HAS_PSEUDO_CLASS_TYPE:
154 return hasMatchingPaths(
155 fiber,
156 ((selector: any): HasPseudoClassSelector).value,
157 );
158 case ROLE_TYPE:
159 if (
160 tag === HostComponent ||
161 tag === HostHoistable ||
162 tag === HostSingleton
163 ) {
164 const node = fiber.stateNode;
165 if (
166 matchAccessibilityRole(node, ((selector: any): RoleSelector).value)
167 ) {
168 return true;
169 }
170 }
171 break;
172 case TEXT_TYPE:
173 if (
174 tag === HostComponent ||
175 tag === HostText ||
176 tag === HostHoistable ||
177 tag === HostSingleton
178 ) {
179 const textContent = getTextContent(fiber);
180 if (
181 textContent !== null &&
182 textContent.indexOf(((selector: any): TextSelector).value) >= 0
183 ) {
184 return true;
185 }
186 }
187 break;
188 case TEST_NAME_TYPE:
189 if (
190 tag === HostComponent ||
191 tag === HostHoistable ||
192 tag === HostSingleton
193 ) {
194 const dataTestID = fiber.memoizedProps['data-testname'];
195 if (
196 typeof dataTestID === 'string' &&
197 dataTestID.toLowerCase() ===
198 ((selector: any): TestNameSelector).value.toLowerCase()
199 ) {
200 return true;
201 }
202 }

Callers 3

findPathsFunction · 0.85
hasMatchingPathsFunction · 0.85

Calls 3

matchAccessibilityRoleFunction · 0.90
getTextContentFunction · 0.90
hasMatchingPathsFunction · 0.85

Tested by

no test coverage detected