Cavy

Cavy

  • Documentation
  • API
  • GitHub
  • Roadmap
  • FAQ

›API reference

Getting Started

  • Installing
  • Setting up the Cavy Tester
  • Writing tests

    • Hooking up components
    • Writing test cases
  • Running tests
  • Sample app

API reference

  • Tester Component
  • Test Hooks
  • Test Helpers
  • CLI Commands
  • Filtering tests
  • Cavy Native Reporter

Guides

  • Specifing a custom app entry point
  • Writing your own spec helpers
  • Writing your own custom reporter
  • Cavy Native Reporter

    • Using Cavy Native Reporter
    • iOS XCTest example (Obj-C)
    • iOS XCTest example (Swift)
    • Android example (JUnit)

Tester Component

As detailed in Setting up the Cavy Tester, your app should be wrapped inside a <Tester> component within index.test.js (or your app entry point). This creates a testable version of your app!

As well as the required specs and store, there are a number of optional props you can pass into the <Tester> to change the way Cavy runs tests. These are detailed below:

Props

NameTypeDescriptionDefault
specs (required)Array(Function)An array of your spec functions-
store (required)TestHookStoreA store of references to UI components in your app-
clearAsyncStorageBooleanIf true, clears AsyncStorage between each test e.g. to remove a logged in userfalse
onlyArray(String)An array of the test tags you'd like to include in the test run. If null, all tests are run. See Filtering tests for examples.null
reporterFunctionCalled once all tests have finished. Takes the test report as an argument. If undefined, Cavy will send a test report to cavy-cli if it is running.undefined
startDelayIntegerTime in milliseconds before test execution begins0
waitTimeIntegerTime in milliseconds that your tests should wait to find a component2000

Example

// index.test.js
import { Tester, TestHookStore } from 'cavy';

import MyFeatureSpec from './specs/MyFeatureSpec';
import OtherFeatureSpec from './specs/OtherFeatureSpec';
import App from './App';

const testHookStore = new TestHookStore();

export default class AppWrapper extends React.Component {
  render() {
    return (
      <Tester
        specs={[MyFeatureSpec, OtherFeatureSpec]}
        store={testHookStore}
        clearAsyncStorage={true}
        only={['focus']}
        startDelay={5000}
        waitTime={5000}
      >
        <App />
      </Tester>
    );
  }
}
← Sample appTest Hooks →
  • Props
  • Example
Pixie Labs
Docs
Getting StartedGuidesAPI Reference
Community
HelpContributorsFurther reading
More
GitHub
StarFollow @pixielabsTweet
Cavy
Copyright © 2021 Pixie Labs