You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a rule that warns against bad patterns which do not use the Smart Assertion Query mechanism when using the getReact() client function.
Problem & Goal
If using testcafe-react-selectors, you can retrieve the React Component State through a ReactSelector("MyComponent").getReact() call. If the statement is prepended with await then it will return a static object of the current state of react component upon the resolution of the client function. In the case react was still processing this could cause brittle test cases. Recommend using the Smart Assertion pattern through the use of getReact() and passing the client function directly into the t.expect() method.
The goal is to prevent brittle test cases by enabling the Smart Assertion callback to use the ClientFunction returned by getReact() inside t.expect()'s.
Expected behavior
// page.test.js -- invalid codeimport{ReactSelector}from'testcafe-react-selectors';fixture`TODO list test`.page('http://localhost:1337');test('Check list item',asynct=>{constel=ReactSelector('TodoList');constcomponent=awaitel.getReact();awaitt.expect(component.props.priority).eql('High');awaitt.expect(component.state.isActive).eql(false);awaitt.expect(component.key).eql('componentID');});
# Run
eslint ./page.test.js
// page.test.js -- correct codeimport{ReactSelector}from'testcafe-react-selectors';fixture`TODO list test`.page('http://localhost:1337');test('Check list item',asynct=>{constel=ReactSelector('TodoList');constcomponent=el.getReact();// Returns ClientFunction()// Smart Assertion Query Mechanism enabledawaitt.expect(component.props.priority).eql('High');awaitt.expect(component.state.isActive).eql(false);awaitt.expect(component.key).eql('componentID');// Alternatives without reuse// await t.expect(el.getReact(({ state }) => state.isActive)).eql(false);// await t.expect(el.getReact().key).eql('componentID');});
The text was updated successfully, but these errors were encountered:
Feature Request
Create a rule that warns against bad patterns which do not use the Smart Assertion Query mechanism when using the
getReact()
client function.Problem & Goal
If using
testcafe-react-selectors
, you can retrieve the React Component State through aReactSelector("MyComponent").getReact()
call. If the statement is prepended withawait
then it will return a static object of the current state of react component upon the resolution of the client function. In the case react was still processing this could cause brittle test cases. Recommend using the Smart Assertion pattern through the use ofgetReact()
and passing the client function directly into thet.expect()
method.The goal is to prevent brittle test cases by enabling the Smart Assertion callback to use the
ClientFunction
returned bygetReact()
insidet.expect()
's.Expected behavior
# Run eslint ./page.test.js
The text was updated successfully, but these errors were encountered: