|
| 1 | +/* eslint-disable no-console */ |
1 | 2 | import * as React from 'react';
|
2 | 3 | import { View, Text, Pressable, TouchableOpacity } from 'react-native';
|
3 | 4 | import { render } from '../..';
|
4 | 5 |
|
| 6 | +type ConsoleLogMock = jest.Mock<typeof console.log>; |
| 7 | + |
| 8 | +beforeEach(() => { |
| 9 | + jest.spyOn(console, 'warn').mockImplementation(() => {}); |
| 10 | +}); |
| 11 | + |
5 | 12 | const TEXT_LABEL = 'cool text';
|
6 | 13 |
|
7 | 14 | const Typography = ({ children, ...rest }: any) => {
|
@@ -251,3 +258,97 @@ test('byA11yState queries support hidden option', () => {
|
251 | 258 | `"Unable to find an element with expanded state: false"`
|
252 | 259 | );
|
253 | 260 | });
|
| 261 | + |
| 262 | +test('*ByA11yState deprecation warnings', () => { |
| 263 | + const mockCalls = (console.warn as ConsoleLogMock).mock.calls; |
| 264 | + const view = render(<View accessibilityState={{ disabled: true }} />); |
| 265 | + |
| 266 | + view.getByA11yState({ disabled: true }); |
| 267 | + expect(mockCalls[0][0]).toMatchInlineSnapshot(` |
| 268 | + "getByA11yState(...) is deprecated and will be removed in the future. |
| 269 | +
|
| 270 | + Use getByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." |
| 271 | + `); |
| 272 | + |
| 273 | + view.getAllByA11yState({ disabled: true }); |
| 274 | + expect(mockCalls[1][0]).toMatchInlineSnapshot(` |
| 275 | + "getAllByA11yState(...) is deprecated and will be removed in the future. |
| 276 | +
|
| 277 | + Use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." |
| 278 | + `); |
| 279 | + |
| 280 | + view.queryByA11yState({ disabled: true }); |
| 281 | + expect(mockCalls[2][0]).toMatchInlineSnapshot(` |
| 282 | + "queryByA11yState(...) is deprecated and will be removed in the future. |
| 283 | +
|
| 284 | + Use queryByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." |
| 285 | + `); |
| 286 | + |
| 287 | + view.queryAllByA11yState({ disabled: true }); |
| 288 | + expect(mockCalls[3][0]).toMatchInlineSnapshot(` |
| 289 | + "queryAllByA11yState(...) is deprecated and will be removed in the future. |
| 290 | +
|
| 291 | + Use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." |
| 292 | + `); |
| 293 | + |
| 294 | + view.findByA11yState({ disabled: true }); |
| 295 | + expect(mockCalls[4][0]).toMatchInlineSnapshot(` |
| 296 | + "findByA11yState(...) is deprecated and will be removed in the future. |
| 297 | +
|
| 298 | + Use findByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." |
| 299 | + `); |
| 300 | + |
| 301 | + view.findAllByA11yState({ disabled: true }); |
| 302 | + expect(mockCalls[5][0]).toMatchInlineSnapshot(` |
| 303 | + "findAllByA11yState(...) is deprecated and will be removed in the future. |
| 304 | +
|
| 305 | + Use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." |
| 306 | + `); |
| 307 | +}); |
| 308 | + |
| 309 | +test('*ByAccessibilityState deprecation warnings', () => { |
| 310 | + const mockCalls = (console.warn as ConsoleLogMock).mock.calls; |
| 311 | + const view = render(<View accessibilityState={{ disabled: true }} />); |
| 312 | + |
| 313 | + view.getByAccessibilityState({ disabled: true }); |
| 314 | + expect(mockCalls[0][0]).toMatchInlineSnapshot(` |
| 315 | + "getByAccessibilityState(...) is deprecated and will be removed in the future. |
| 316 | +
|
| 317 | + Use getByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." |
| 318 | + `); |
| 319 | + |
| 320 | + view.getAllByAccessibilityState({ disabled: true }); |
| 321 | + expect(mockCalls[1][0]).toMatchInlineSnapshot(` |
| 322 | + "getAllByAccessibilityState(...) is deprecated and will be removed in the future. |
| 323 | +
|
| 324 | + Use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." |
| 325 | + `); |
| 326 | + |
| 327 | + view.queryByAccessibilityState({ disabled: true }); |
| 328 | + expect(mockCalls[2][0]).toMatchInlineSnapshot(` |
| 329 | + "queryByAccessibilityState(...) is deprecated and will be removed in the future. |
| 330 | +
|
| 331 | + Use queryByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." |
| 332 | + `); |
| 333 | + |
| 334 | + view.queryAllByAccessibilityState({ disabled: true }); |
| 335 | + expect(mockCalls[3][0]).toMatchInlineSnapshot(` |
| 336 | + "queryAllByAccessibilityState(...) is deprecated and will be removed in the future. |
| 337 | +
|
| 338 | + Use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." |
| 339 | + `); |
| 340 | + |
| 341 | + view.findByAccessibilityState({ disabled: true }); |
| 342 | + expect(mockCalls[4][0]).toMatchInlineSnapshot(` |
| 343 | + "findByAccessibilityState(...) is deprecated and will be removed in the future. |
| 344 | +
|
| 345 | + Use findByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." |
| 346 | + `); |
| 347 | + |
| 348 | + view.findAllByAccessibilityState({ disabled: true }); |
| 349 | + expect(mockCalls[5][0]).toMatchInlineSnapshot(` |
| 350 | + "findAllByAccessibilityState(...) is deprecated and will be removed in the future. |
| 351 | +
|
| 352 | + Use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." |
| 353 | + `); |
| 354 | +}); |
0 commit comments