Skip to content

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