Override accessibility environment values in SwiftUI snapshot tests?

97 Views Asked by At

I'm writing snapshot tests for SwiftUI views using the Point-Free snapshot test library. I'd like to test that my views respond correctly to the following SwiftUI environment properties:

  • accessibilityDifferentiateWithoutColor
  • accessibilityReduceTransparency
  • accessibilityReduceMotion
  • accessibilityInvertColors

How can I override these values in my tests?

1

There are 1 best solutions below

0
Zev Eisenberg On

There are public-but-undocumented, underscored versions of these symbols that can be used to override their values in tests:

  • _accessibilityDifferentiateWithoutColor
  • _accessibilityReduceTransparency
  • _accessibilityReduceMotion
  • _accessibilityInvertColors

Usage:

someView
    .environment(\._accessibilityShowButtonShapes, true)

It is my understanding that these values are intentionally provided by Apple for testing purposes.