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

Harness Support for Functional Widgets and Middleware #411

Merged
merged 5 commits into from
Jun 25, 2019

Conversation

agubler
Copy link
Member

@agubler agubler commented Jun 25, 2019

Type: feature

The following has been addressed in the PR:

Description:

Harness support for functional widgets and middleware. Introduces a new options argument to the harness that can be used to specify mocks for the widget under tests middleware. The middleware argument accepts a tuple with the "real" middleware function, against the mock middleware function.

const h = harness(() => <MyWidget />, { 
	middleware: [ [ realMiddleware, mockMiddleware ] ] 
});

Mock middleware are also middleware created using the @dojo/framework/core/vdom#create function.

Core middleware from @dojo/framework/core/vdom, such as diffProperty, invalidator, destroy are automatically mocked by the harness.

There are mock factories for resize, intersection and node available from @dojo/framework/testing/mocks/middleware, these are used like this:

const resizeMock = createResizeMock();
const factory = create({ resize });
const App = factory(({ middleware: { resize } }) => {
	const rects = resize.get('root');
	return <div key="root">{JSON.stringify(rects)}</div>;
});
const h = harness(() => <App key="app" />, { middleware: [[resize, resizeMock]] });
h.expect(() => <div key="root">null</div>);
resizeMock('root', { width: 100 });
h.expect(() => <div key="root">{`{"width":100}`}</div>);
resizeMock('root', { width: 101 });
h.expect(() => <div key="root">{`{"width":101}`}</div>);

Related to #352

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

Successfully merging this pull request may close these issues.

2 participants