React Page Object screenshot

React Page Object

Updated: 20 May 2017
23 Stars

Declarative UI testing for React

Overview:

The React Page Object library is a powerful tool designed for writing integration tests in React applications. It seamlessly integrates with any test runner or assertion library that works with Enzyme, making it a versatile choice for React developers. Whether you’re new to testing or are looking to streamline your testing process, this library offers a robust set of features to help you effectively manage and test your React components.

The installation process is straightforward, requiring you to install Enzyme alongside its peer dependencies—react-dom and react-addons-test-utils—if they’re not already part of your project. With the right setup, you’ll gain access to a comprehensive API that simplifies your testing workflow, allowing for efficient interaction and manipulation of React components.

Features:

  • Page Construction: Quickly create Page objects using the constructor(reactElement, options) method, facilitating easy management of your test components.

  • Element Interaction: Utilize methods like clickButton, clickLink, and choose to simulate user interactions with components like buttons and radio buttons.

  • Input Handling: Fill in form elements with methods such as fillIn and fillInTextarea, allowing for realistic user input scenarios in tests.

  • Element Querying: Use findWrapperForCheck and similar methods to efficiently locate specific elements within your React component, streamlining the testing process.

  • Asynchronous Testing: The waitUntil method allows you to pause the test execution until certain conditions are met, greatly aiding in the testing of asynchronous components.

  • Content Validation: The content and contentMatches methods let you easily validate the text output of your components, ensuring they render the expected content.

  • Current Path Retrieval: Use the currentPath method to obtain the current URL path during testing, useful for validating routing functionality.

  • Destruction Method: The destroy method allows for easy cleanup of Page objects, ensuring that your tests do not interfere with one another.