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

Expecta matchers for ios-snapshot-test-case.

License

NotificationsYou must be signed in to change notification settings

dblock/ios-snapshot-test-case-expecta

Repository files navigation

Expecta matchers forios-snapshot-test-case.

Build and test

Usage

AddExpecta+Snapshots to your Podfile, the latestFBSnapshotTestCase will come in as a dependency.

pod'Expecta+Snapshots'

App setup

Useexpect(view).to.recordSnapshotNamed(@"unique snapshot name") to record a snapshot andexpect(view).to.haveValidSnapshotNamed(@"unique snapshot name") to check it.

If you project was compiled with Specta included, you have two extra methods that use the spec hierarchy to generate the snapshot name for you:recordSnapshot() andhaveValidSnapshot(). You should only call these once perit() block.

If you need theusesDrawViewHierarchyInRect property in order to correctly render UIVisualEffect, UIAppearance and Size Classes, call[Expecta setUsesDrawViewHierarchyInRect:NO]; insidebeforeAll.

#defineEXP_SHORTHAND#include<Specta/Specta.h>#include<Expecta/Expecta.h>#include<Expecta+Snapshots/EXPMatchers+FBSnapshotTest.h>#include"FBExampleView.h"SpecBegin(FBExampleView)describe(@"manual matching", ^{it(@"matches view", ^{        FBExampleView *view = [[FBExampleViewalloc]initWithFrame:CGRectMake(0,0,64,64)];expect(view).to.recordSnapshotNamed(@"FBExampleView");expect(view).to.haveValidSnapshotNamed(@"FBExampleView");    });it(@"doesn't match a view", ^{        FBExampleView *view = [[FBExampleViewalloc]initWithFrame:CGRectMake(0,0,64,64)];expect(view).toNot.haveValidSnapshotNamed(@"FBExampleViewDoesNotExist");    });});describe(@"test name derived matching", ^{it(@"matches view", ^{        FBExampleView *view = [[FBExampleViewalloc]initWithFrame:CGRectMake(0,0,64,64)];expect(view).to.recordSnapshot();expect(view).to.haveValidSnapshot();    });it(@"doesn't match a view", ^{        FBExampleView *view = [[FBExampleViewalloc]initWithFrame:CGRectMake(0,0,64,64)];expect(view).toNot.haveValidSnapshot();    });});SpecEnd

Approximation support

If for some reason you want to specify a tolerance for your test, you can use either named or unnamed matchers, where thetolerance parameter is aCGFloat in the interval[0, 1] and it represents the minimum ratio of unmatched points by the total number of points in your snapshot. In the example below, a tolerance of0.01 means ourview could be up to1% different from the reference image.

expect(view).to.haveValidSnapshotWithTolerance(0.01);expect(view).to.haveValidSnapshotNamedWithTolerance(@"unique snapshot name",0.01);

Sane defaults

EXPMatchers+FBSnapshotTest will automatically figure out the tests folder, andadd a reference image directory, if you'd like to override this, you should include abeforeAll block setting thesetGlobalReferenceImageDir in each file containing tests.

beforeAll(^{    setGlobalReferenceImageDir(FB_REFERENCE_IMAGE_DIR);});

Example

A complete project can be found inFBSnapshotTestCaseDemo.

Notably, take a look atFBSnapshotTestCaseDemoSpecs.m for a complete example, which is an expanded Specta version version ofFBSnapshotTestCaseDemoTests.m.

Finally you can consult the tests forARTiledImageView orNAMapKit.

License

MIT, seeLICENSE

About

Expecta matchers for ios-snapshot-test-case.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors17


[8]ページ先頭

©2009-2025 Movatter.jp