DevExpress/testcafe-react-selectors hiện có 202 sao trên GitHub, viết chủ yếu bằng JavaScript. TestCafe selector extensions for React apps.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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:
DevExpress/testcafe-react-selectors có bao nhiêu sao?
DevExpress/testcafe-react-selectors có 202 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/DevExpress/testcafe-react-selectors. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
DevExpress/testcafe-react-selectors có phải mã nguồn mở không?
Có — DevExpress/testcafe-react-selectors phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/DevExpress/testcafe-react-selectors.
DevExpress/testcafe-react-selectors còn đang phát triển không?
Commit gần nhất trên DevExpress/testcafe-react-selectors là 6 tháng trước (theo timestamp GitHub). Repo có 41 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
DevExpress/testcafe-react-selectors là gì?
DevExpress/testcafe-react-selectors (DevExpress/testcafe-react-selectors) là dự án JavaScript trên GitHub. Theo mô tả gốc: TestCafe selector extensions for React apps.
DevExpress/testcafe-react-selectors so với các dự án Frontend khác thế nào?
DevExpress/testcafe-react-selectors được TopGit xếp vào nhóm Frontend, với 202 sao GitHub và viết bằng JavaScript. Xem trang chủ đề Frontend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
Đọc thêm về DevExpress/testcafe-react-selectors ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/DevExpress/testcafe-react-selectors là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về testcafe-react-selectors?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về testcafe-react-selectors.