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

Allow context injection in core-block tests #7108

Closed
wants to merge 1 commit into from
Closed

Allow context injection in core-block tests #7108

wants to merge 1 commit into from

Conversation

mirka
Copy link
Member

@mirka mirka commented Jun 3, 2018

Description

This adds the ability to inject context when testing core-block components.

This will allow components using a context-dependent HOC (like withAPIData) to be snapshot tested using the same blockEditRender() test helper.

Example of intended usage

For a quick test, you can check out this commit and try the following as a test case in core-blocks/file/test/index.js

test( 'block edit matches snapshot', () => {
	const contextTypes = {
		getAPISchema: noop,
		getAPIPostTypeRestBaseMapping: noop,
		getAPITaxonomyRestBaseMapping: noop,
	};

	const context = Object.assign( {}, contextTypes );
	context.getAPISchema = () => {
		return { routes: null };
	};

	const wrapper = blockEditRender( name, settings, context, contextTypes );

	expect( wrapper ).toMatchSnapshot();
} );

@gziolo
Copy link
Member

gziolo commented Jun 5, 2018

I just wanted to raise one issue with this proposal. Please note that it is using Legacy Context which is going to be deprecated in React 17. In my opinion, we shouldn't be investing time in extending our test in code that won't work in the future. We should rather to seek an alternative approach for File block to avoid using withAPIData which we are slowly replacing with wp.data.withSelect.

@gziolo gziolo added the [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. label Jun 5, 2018
@gziolo gziolo mentioned this pull request Jun 5, 2018
11 tasks
@gziolo
Copy link
Member

gziolo commented Jun 5, 2018

I came to the conclusion that we should close this one after leaving my comment on #6805:

You should be rather using getMedia selector instead of withAPIData which is going to be deprecated as soon as we find a way to port all existing code that handles REST API requests. This will also remove the need to introducing changes proposed in #7108.

@gziolo gziolo closed this Jun 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants