react-unit-test-generator
Version:
react-unit-test-generator is a helper for writing unit tests for React apps. Its main goal is to automatically generate a suite of the most common test cases for a given component.
17 lines (15 loc) • 559 B
JavaScript
import clickButton from '../../helpers/clickButton';
import { noIdentifierSpecified } from '../warnings';
export default function testRedirectToUrl(element) {
if (!element.identifier) {
return noIdentifierSpecified(element);
}
return `
it('redirects to "${element.redirectTo}" on "${element.label}" button click', () => {
window.history.pushState({}, '', '${element.redirectTo}');
${clickButton(element.identifier)}
component.update();
expect(window.location.href).toContain('${element.redirectTo}');
});
`;
}