On GitHub, DevExpress/testcafe-react-selectors has picked up 202 stars, Frontend, JavaScript. TestCafe selector extensions for React apps.
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
This plugin provides selector extensions that make it easier to test ReactJS components with TestCafe. These extensions allow you to select page elements in a way that is native to React.
Install
$ npm install testcafe-react-selectors
Usage
Wait for application to be ready to run tests
Creating selectors for ReactJS components
Selecting elements by the component name
Selecting nested components
Selecting components by the component key
Selecting components by display name
Selecting components by property values
Properties whose values are objects
Searching for nested components
Combining with regular TestCafe selectors
Obtaining component's props and state
TypeScript Generic Selector
Composite Types in Props and State
Limitations
Wait for application to be ready to run tests
To wait until the React's component tree is loaded, add the waitForReact method to fixture's beforeEach hook.
The default timeout for waitForReact is 10000 ms. You can specify a custom timeout value:
await waitForReact(5000);
If you need to call a selector from a Node.js callback, pass the current test controller as the second argument in the waitForReact function:
import { waitForReact } from 'testcafe-react-selectors';
fixture `App tests`
.page('http://react-app-url')
.beforeEach(async t => {
await waitForReact(5000, t);
});
The test controller will be assigned to the boundTestRun function's option. Otherwise, TestCafe would throw the following error: ClientFunction cannot implicitly resolve the test run in context of which it should be executed. See the TestCafe documentation for further details.
Creating selectors for ReactJS components
ReactSelector allows you to select page elements by the name of the component class or the nested component element.
Warning: if you specify a DOM element's tag name, React selectors search for the element among the component's children without looking into nested components. For instance, for the JSX above the ReactSelector('TodoApp div') selector will be equal to Selector('.todo-app > div').
Selecting components by the component key
To obtain a component by its key, use the withKey method.
import { ReactSelector } from 'testcafe-react-selectors';
const item = ReactSelector('TodoItem').withKey('HighPriority');
Selecting components by display name
You can select elements by the component's displayName.
For instance, consider the TodoList component whose displayName class property is specified as follows:
In this instance, you can use todo-list-display-name to identify TodoList.
import { ReactSelector } from 'testcafe-react-selectors';
const list = ReactSelector('todo-list-display-name');
Selecting components by property values
React selectors allow you to select elements that have a specific property value. To do this, use the withProps method. You can pass the property and its value as two parameters or an object.
Prior to version 3.0.0, withProps checked if objects are strictly equal when comparing them. Since 3.0.0, withProps checks for partial equality. To test objects for strict equality, specify the exactObjectMatch option.
The following example returns the componentName component because the objProp property values are strictly equal and exactObjectMatch is set to true.
You can search for a desired subcomponent or DOM element among the component's children using the .findReact(element) method. The method takes the subcomponent name or tag name as a parameter.
The following sample demonstrates how to obtain the TodoItem subcomponent.
import { ReactSelector } from 'testcafe-react-selectors';
const component = ReactSelector('TodoApp');
const div = component.findReact('div');
const subComponent = div.findReact('TodoItem');
You can call the .findReact method in a chain, for example:
import { ReactSelector } from 'testcafe-react-selectors';
const subComponent = ReactSelector('TodoApp').findReact('div').findReact('TodoItem');
You can also combine .findReact with regular selectors and other) methods like .find or .withText, for example:
import { ReactSelector } from 'testcafe-react-selectors';
const subComponent = ReactSelector('TodoApp').find('div').findReact('TodoItem');
Combining with regular TestCafe selectors
Selectors returned by the ReactSelector constructor are recognized as TestCafe selectors. You can combine them with regular selectors and filter with .withText, .nth, .find and other functions. To search for elements within a component, you can use the following combined approach.
import { ReactSelector } from 'testcafe-react-selectors';
var itemsCount = ReactSelector('TodoApp').find('.items-count span');
Example
Let's use the API described above to add a task to a Todo list and check that the number of items changed.
import { ReactSelector } from 'testcafe-react-selectors';
fixture `TODO list test`
.page('http://localhost:1337');
test('Add new task', async t => {
const todoTextInput = ReactSelector('TodoInput');
const todoItem = ReactSelector('TodoList TodoItem');
await t
.typeText(todoTextInput, 'My Item')
.pressKey('enter')
.expect(todoItem.count).eql(3);
});
Obtaining component's props and state
As an alternative to testcafe snapshot properties, you can obtain state, props or key of a ReactJS component.
To obtain component's properties, state and key, use the React selector's .getReact() method.
The .getReact() method returns a client function. This function resolves to an object that contains component's properties (excluding properties of its children), state and key.
The returned client function can be passed to assertions activating the Smart Assertion Query mechanism.
Example
import { ReactSelector } from 'testcafe-react-selectors';
fixture `TODO list test`
.page('http://localhost:1337');
test('Check list item', async t => {
const el = ReactSelector('TodoList');
const component = await el.getReact();
await t.expect(component.props.priority).eql('High');
await t.expect(component.state.isActive).eql(false);
await t.expect(component.key).eql('componentID');
});
As an alternative, the .getReact() method can take a function that returns the required property, state or key. This function acts as a filter. Its argument is an object returned by .getReact(), i.e. { props: ..., state: ..., key: ...}.
If a component's props and state include other composite types, you can create your own type definitions for them. Then pass these definitions to ReactComponent as type arguments.
The following example shows custom Props and State type definitions. The State type uses another composite type - Option.
testcafe-react-selectors support ReactJS starting with version 16. To check if a component can be found, use the react-dev-tools extension.
Search for a component starts from the root React component, so selectors like ReactSelector('body MyComponent') will return null.
ReactSelectors need class names to select components on the page. Code minification usually does not keep the original class names. So you should either use non-minified code or configure the minificator to keep class names.
For babel-minify, add the following options to the configuration:
How active is development on DevExpress/testcafe-react-selectors?
The most recent commit recorded on DevExpress/testcafe-react-selectors was 9 months ago, based on the GitHub push timestamp. The repository has 40 forks — one of the better signals of community interest.
How does DevExpress/testcafe-react-selectors compare to other Frontend projects?
DevExpress/testcafe-react-selectors is tracked by TopGit in the Frontend category, with 202 GitHub stars and written in JavaScript. Browse the Frontend topic page on TopGit to compare it against similar projects by stars and activity.
How many stars does DevExpress/testcafe-react-selectors have?
DevExpress/testcafe-react-selectors has 202 GitHub stars — refresh the page for the live number, or check github.com/DevExpress/testcafe-react-selectors. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is DevExpress/testcafe-react-selectors open source?
Yes — DevExpress/testcafe-react-selectors ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/DevExpress/testcafe-react-selectors.
What is DevExpress/testcafe-react-selectors?
DevExpress/testcafe-react-selectors (DevExpress/testcafe-react-selectors) is a JavaScript project on GitHub. From the project's own README: TestCafe selector extensions for React apps.
Where do I read more about DevExpress/testcafe-react-selectors?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/DevExpress/testcafe-react-selectors is the definitive source.
Read full README in the tab above.
Is testcafe-react-selectors worth your time?
ChatGPT, Claude and Perplexity can all read this page. Ask one of them what it makes of testcafe-react-selectors.