-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b0438a
commit 6eff290
Showing
82 changed files
with
828 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 0 additions & 82 deletions
82
DemoApp/DemoApp.xcodeproj/xcshareddata/xcschemes/DemoApp.xcscheme
This file was deleted.
Oops, something went wrong.
59 changes: 0 additions & 59 deletions
59
DemoApp/DemoApp.xcodeproj/xcshareddata/xcschemes/DemoAppTests.xcscheme
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions
27
Examples/DemoApp/DemoApp/TestViews/ScrollingTextView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// ScrollingTextView.swift | ||
// DemoApp | ||
// | ||
// Created by Noah Martin on 8/24/24. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
struct ScrollingTextView: NSViewRepresentable { | ||
func makeNSView(context: Context) -> some NSView { | ||
let textView = NSTextView() | ||
textView.string = "test" | ||
let scrollView = NSScrollView() | ||
scrollView.documentView = textView | ||
return scrollView | ||
} | ||
|
||
func updateNSView(_ nsView: NSViewType, context: Context) { } | ||
} | ||
|
||
struct ScrollingTextView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ScrollingTextView() | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Unit Test Migration | ||
|
||
This example shows how to migrate from swift-snapshot-testing to preview providers. The example app contains a unit test target `UnitTestMigrationTests` with one [snapshot test](https://github.com/EmergeTools/SnapshotPreviews-iOS/blob/main/Examples/UnitTestMigration/UnitTestMigrationTests/ExampleSnapshotTest.swift). It has been migrated by copying/pasting the file into the main app target as [ExampleSnapshotTest_Migrated.swift](https://github.com/EmergeTools/SnapshotPreviews-iOS/blob/main/Examples/UnitTestMigration/UnitTestMigration/ExampleSnapshotTest_Migrated.swift). The test is modified by removing the XCTest/SnapshotTesting importants, changing the base class to `SnapshotTest` and adding the conformance to `PreviewProvider`. | ||
|
||
## Migrating your own tests | ||
|
||
1. Add the file [SnapshotTest.swift](https://github.com/EmergeTools/SnapshotPreviews-iOS/blob/main/Examples/UnitTestMigration/UnitTestMigration/SnapshotTest.swift) to your app, this does the heavy lifting of converting snapshot test function calls into previews. | ||
2. Copy your test file from the unit test target to your application. | ||
3. Remove imports of `XCTest` and `SnapshotTesting`. | ||
4. Change the base class from `XCTestCase` to `SnapshotTest` and add a conformce to `PreviewProvider`. | ||
|
||
Here’s a complete example of a migrated test: | ||
|
||
```swift | ||
import SwiftUI | ||
|
||
// Add the conformance to `PreviewProvider` when extending `SnapshotTest` | ||
// The `SnapshotTest` base class automatically handles turning calls to | ||
// assertSnapshot into previews. | ||
class ExampleSnapshotTest: SnapshotTest, PreviewProvider { | ||
|
||
func testContentViewSnapshot() { | ||
assertSnapshot(of: ContentView(), as: .image) | ||
} | ||
} | ||
``` |
Oops, something went wrong.