Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 22, 2025. It is now read-only.

Nimble matchers for FBSnapshotTestCase.

License

NotificationsYou must be signed in to change notification settings

travelperk/Nimble-Snapshots

 
 

Repository files navigation

GitHub Actions CICocoapods compatibleSPM compatibleCarthage compatibleLicense

Nimble matchers foriOSSnapshotTestCase.Originally derived fromExpecta Matchers for FBSnapshotTestCase.

Installing

CocoaPods

You need to be using CocoaPods 0.36 Beta 1 or higher. YourPodfile should looksomething like the following.

platform:ios,'10.0'source'https://github.com/CocoaPods/Specs.git'# Whichever pods you need for your app go here.target'YOUR_APP_NAME_HERE_Tests',:exclusive=>truedopod'Nimble-Snapshots'pod'Quick'# if you want to use it with Quickend

Then run:

$ pod install

Carthage

You need to be using Carthage 0.18 or higher. YourCartfile (orCartfile.private) should looksomething like the following.

github"Quick/Quick" ~>4.0github"Quick/Nimble" ~>9.2github"uber/ios-snapshot-test-case""8.0.0"github"ashfurrow/Nimble-Snapshots"

Then run:

$ carthage bootstrap --use-xcframeworks --platform iOS

Swift Package Manager

To addNimble-Snapshots as a dependency, you have to add it to the dependencies of yourPackage.swift file and refer to that dependency in your target.

import PackageDescriptionletpackage=Package(    name:"<Your Product Name>",    dependencies:[.package(url:"https://github.com/ashfurrow/Nimble-Snapshots",.upToNextMajor(from:"9.0.0"))],    targets:[.target(            name:"<Your Target Name>",            dependencies:["Nimble-Snapshots"]),])

Use

Your tests will look something like the following.

import Quickimport Nimbleimport Nimble_Snapshotsimport UIKitclassMySpec:QuickSpec{overridefunc spec(){describe("in some context"){it("has valid snapshot"){letview=... // some view you want to testexpect(view).to(haveValidSnapshot())}}}}

There are some options for testing the validity of snapshots. Snapshots can begiven a name:

expect(view).to(haveValidSnapshot(named:"some custom name"))

We also have a prettier syntax for custom-named snapshots:

expect(view)==snapshot("some custom name")

To record snapshots, just replacehaveValidSnapshot() withrecordSnapshot()andhaveValidSnapshot(named:) withrecordSnapshot(named:). We also have ahandy emoji operator.

📷(view)📷(view,"some custom name")

By default, this pod will put the reference images inside aReferenceImagesdirectory; we try to put this in a place that makes sense (inside your unittests directory). If we can't figure it out, or if you want to use your owndirectory instead, callsetNimbleTestFolder() with the name of the directoryin your unit test's path that we should use. For example, if the tests are inApp/AppTesting/, you can call it withAppTesting.

If you have any questions or run into any trouble, feel free to open an issueon this repo.

Dynamic Type

Testing Dynamic Type manually is boring and no one seems to remember doing itwhen implementing a view/screen, so you can have snapshot tests according tocontent size categories.

In order to use Dynamic Type testing, make sure to provide a validHost Application in your testing target.

Then you can use thehaveValidDynamicTypeSnapshot andrecordDynamicTypeSnapshot matchers:

// expect(view).to(recordDynamicTypeSnapshot()expect(view).to(haveValidDynamicTypeSnapshot())// You can also just test some sizes:expect(view).to(haveValidDynamicTypeSnapshot(sizes:[UIContentSizeCategoryExtraLarge]))// If you prefer the == syntax, we got you covered too:expect(view)==dynamicTypeSnapshot()expect(view)==dynamicTypeSnapshot(sizes:[UIContentSizeCategoryExtraLarge])

Note that this will post anUIContentSizeCategoryDidChangeNotification,so your views/view controllers need to observe that and update themselves.

For more info on usage, check out thedynamic type tests.

Dynamic Size

Testing the same view with many sizes is easy but error prone. It easy to fix one teston change and forget the others. For this we create a easy way to tests all sizes at same time.

You can use the newhaveValidDynamicSizeSnapshot andrecordDynamicSizeSnapshotmatchers to test multiple sizes at once:

letsizes=["SmallSize":CGSize(width:44, height:44),"MediumSize":CGSize(width:88, height:88),"LargeSize":CGSize(width:132, height:132)]// expect(view).to(recordDynamicSizeSnapshot(sizes: sizes))expect(view).to(haveValidDynamicSizeSnapshot(sizes: sizes))// You can also just test some sizes:expect(view).to(haveValidDynamicSizeSnapshot(sizes: sizes))// If you prefer the == syntax, we got you covered too:expect(view)==snapshot(sizes: sizes)expect(view)==snapshot(sizes: sizes)

By default, the size will be set on the view using the frame property. To change this behavioryou can use theResizeMode enum:

publicenumResizeMode{case framecase constrainscase block(resizeBlock:(UIView,CGSize)->Void)case custom(viewResizer:ViewResizer)}

To use the enum you canexpect(view) == dynamicSizeSnapshot(sizes: sizes, resizeMode: newResizeMode).For custom behavior you can useResizeMode.block. The block will be call on every resize. Or you canimplement theViewResizer protocol and resize yourself.The custom behavior can be used to record the views too.

For more info on usage, check thedynamic sizes tests.

Packages

No packages published

Languages

  • Swift95.4%
  • Ruby3.3%
  • Objective-C1.3%

[8]ページ先頭

©2009-2025 Movatter.jp