Cavy

Cavy

  • Documentation
  • API
  • GitHub
  • Roadmap
  • FAQ

›Guides

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)

Writing your own spec helpers

If you'd like to test something that's not included in the Cavy helpers, you can write your own spec helper function.

Your function will need to be asynchronous and should throw an error in situations where you want the test to fail.

For example, the following tests whether a <Button> component is disabled:

// specs/helpers.js

export async function isDisabled(button) {
  if (!button.props.disabled) {
    throw new Error(`Button not disabled.`);
  };
}

Then in your spec, you can import your helper and pass in the component using findComponent():

// specs/AppSpec.js

import { isDisabled } from './helpers';

export default function(spec) {
  spec.describe('The button', function() {
    spec.it('is disabled', async function() {
      const button = await spec.findComponent('Scene.Button');
      // Use your spec helper to test that the button is disabled
      await isDisabled(button);
    });
  });
}
← Specifing a custom app entry pointWriting your own custom reporter →
Pixie Labs
Docs
Getting StartedGuidesAPI Reference
Community
HelpContributorsFurther reading
More
GitHub
StarFollow @pixielabsTweet
Cavy
Copyright © 2021 Pixie Labs