Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper method for easier testing of child render functions #1567

Open
samends opened this issue Nov 18, 2020 · 0 comments
Open

Add helper method for easier testing of child render functions #1567

samends opened this issue Nov 18, 2020 · 0 comments

Comments

@samends
Copy link
Contributor

samends commented Nov 18, 2020

Enhancement

Suggestion to create a mock function that would allow for easier testing of widgets that have child render functions. For instance the form widget could have a mock function as follows:

export function createMockFormMiddleware(fields: {
	[key: string]: { value?: string; valid?: boolean };
}) {
	return {
		valid: () =>
			Object.keys(fields).reduce((valid, key) => {
				return (
					valid &&
					(fields[key].valid !== undefined
						? (fields[key].valid as boolean)
						: true)
				);
			}, true),
		field: (key: string) => {
			return {
				value: () => fields[key].value || '',
				valid: () => fields[key].valid || true
			};
		}
	};
}

It could then be used to easily set up the form child function' parameters

	it('default renders correctly', () => {
		const r = renderer(() => <Login />);
		r.child(
			WrappedForm,
			createMockFormMiddleware({
				username: { valid: true, value: '' },
				password: { valid: true, value: '' }
			})
		);
		r.expect(baseAssertion);
	});
@samends samends changed the title Adding a mock form function for easier testing Add helper method for easier testing of child render functions Nov 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant