I am trying to test a react component that has a properties that changes when the user logs in. I can't change the login prop from the testcafe suite itself because the user can only login clicking on a magic link that she receives on her email.
Given the example component below, how can I test the Logout button?
Test cafe will always see the isLoggedIn prop as false and it doesn't allow to set components props to some custom value while testing.
header.js
import React from 'react';
const Header = ({ isLoggedIn }) => (
<div>
{isLoggedIn ? (
<h1>text unreachable from testcafe</h1>
<button onClick={logout}>Logout</button>
) : (
<button onClick={login}>Login</button>
)}
</div>
);
export default Header;
test-cafe.js
import { ReactSelector } from 'testcafe-react-selectors';
import { waitForReact } from 'testcafe-react-selectors';
fixture`HEADER`
.page('http://localhost:3000')
.beforeEach(async () => {
await waitForReact();
});
test('Page should load the header', async (t) => {
const App = ReactSelector('App').withProps({ isLoggedIn: true });
const actual = App.find('h1').innerText;
const expected = 'text unreachable from testcafe';
await t.expect(actual).eql(expected);
});