[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-7107":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":18,"compositeScore":20,"rankGlobal":10,"rankLanguage":10,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":24,"hasPages":22,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":33,"readmeContent":34,"aiSummary":35,"trendingCount":16,"starSnapshotCount":16,"syncStatus":36,"lastSyncTime":37,"discoverSource":38},7107,"ViewInspector","nalexn\u002FViewInspector","nalexn","Runtime introspection and unit testing of SwiftUI views","",null,"Swift",2611,189,26,53,0,1,3,8,28.84,"MIT License",false,"0.10.4",true,[26,27,28,29,30,31,32],"best-practices","runtime-typechecking","swift","swift5","swiftui","swiftui-views","unit-testing","2026-06-12 02:01:34","\u003Ch1 align=\"center\">ViewInspector 🕵️‍♂️ for SwiftUI\u003C\u002Fh1>\n\n\u003Cspan align=\"center\">\n  \n![Platform](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fplatform-iOS%20%7C%20macOS%20%7C%20tvOS%20%7C%20watchOS%20%7C%20visionOS-lightgrey) [![codecov](https:\u002F\u002Fcodecov.io\u002Fgh\u002Fnalexn\u002FViewInspector\u002Fbranch\u002Fmaster\u002Fgraph\u002Fbadge.svg)](https:\u002F\u002Fcodecov.io\u002Fgh\u002Fnalexn\u002FViewInspector)\n\n\u003C\u002Fspan>\n\n**ViewInspector** is a library for unit testing SwiftUI views.\nIt allows for traversing a view hierarchy at runtime providing direct access to the underlying `View` structs.\n\n## Why?\n\nSwiftUI view is a function of state. We could provide it with the input but could not verify the output... Until now!\n\n## Helpful links\n\n* **[Inspection guide](guide.md)**\n* **[SwiftUI API coverage](readiness.md)**\n\n## Use cases\n\n### 1. Search the view of a specific type or condition\n\nUse one of the `find` functions to quickly locate a specific view or assert there are none of such:\n\n```swift\ntry sut.inspect().find(button: \"Back\")\n\ntry sut.inspect().findAll(ViewType.Text.self,\n                          where: { try $0.attributes().isBold() })\n```\n\nCheck out [this section](guide.md#dynamic-query-with-find) in the guide for the reference.\n\n### 2. Read the inner state of the standard views\n\nStandard SwiftUI views are no longer a black box:\n\n```swift\nlet sut = Text(\"Completed by \\(72.51, specifier: \"%.1f\")%\").font(.caption)\n\nlet string = try sut.inspect().text().string(locale: Locale(identifier: \"es\"))\nXCTAssertEqual(string, \"Completado por 72,5%\")\n\nXCTAssertEqual(try sut.inspect().text().attributes().font(), .caption)\n```\n\nEach view has its own set of inspectable parameters, you can refer to the [API coverage](readiness.md) document to see what's available for a particular SwiftUI view.\n\n### 3. Verify your custom view's state\n\nObtain a copy of your custom view with actual state and references from the hierarchy of any depth:\n\n```swift\nlet sut = try view.inspect().find(CustomView.self).actualView()\nXCTAssertTrue(sut.viewModel.isUserLoggedIn)\n```\n\nThe library can operate with various types of the view's state, such as `@Binding`, `@State`, `@ObservedObject` and `@EnvironmentObject`.\n\n### 4. Trigger side effects\n\nYou can simulate user interaction by programmatically triggering system-control callbacks:\n\n```swift\ntry sut.inspect().find(button: \"Close\").tap()\n\nlet list = try view.inspect().list()\ntry list[5].view(RowItemView.self).callOnAppear()\n```\n\nThe library provides helpers for writing asynchronous tests for views with callbacks.\n\n## FAQs\n\n### Which views and modifiers are supported?\n\nCheck out the [API coverage](readiness.md).\n\n### Is it using private APIs?\n\n**ViewInspector** is using the official Swift reflection API to dissect the view structures. So it'll be production-friendly even if you could somehow ship the test target to the production.\n\n### How do I add it to my Xcode project?\n\nAssure you're adding the framework to your unit-test target. **Do NOT** add it to the main build target.\n\n#### Swift Package Manager\n\n`https:\u002F\u002Fgithub.com\u002Fnalexn\u002FViewInspector`\n\n#### Carthage\n\n`github \"nalexn\u002FViewInspector\"`\n\n#### CocoaPods\n\n`pod 'ViewInspector'`\n\n### How do I use it in my project?\n\nPlease refer to the [Inspection guide](guide.md). You can also check out my other [project](https:\u002F\u002Fgithub.com\u002Fnalexn\u002Fclean-architecture-swiftui) that harnesses the **ViewInspector** for testing the entire UI.\n\n### Contributions\n\nContributions are welcomed! If you see an unsupported view or modifier, you can either open an issue (so I could prioritize such SwiftUI APIs over the rest), or try to crack it yourself: use the `print(\"\\(Inspector.print(\u003C#view#>) as AnyObject)\")` as the starting point of the investigation.\n","ViewInspector 是一个用于 SwiftUI 视图单元测试的库。它能够在运行时遍历视图层次结构，直接访问底层的 `View` 结构体，支持 iOS、macOS、tvOS、watchOS 和 visionOS 平台。该库允许开发者查找特定类型或条件的视图，读取标准视图的内部状态，并验证自定义视图的状态。此外，还能模拟用户交互触发系统回调，适用于需要对 SwiftUI 应用进行深入测试和调试的场景。通过使用官方 Swift 反射 API，ViewInspector 确保了其在生产环境中的兼容性和稳定性。",2,"2026-06-11 03:10:32","top_language"]