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 unit tests for props to attribute mapping in SSR. #9106

Merged
merged 20 commits into from Mar 19, 2017

Conversation

aickin
Copy link
Contributor

@aickin aickin commented Mar 3, 2017

This PR is a continuation of my port of SSR unit tests into master. There are two parts to this PR:

  1. A bunch of test for the mapping of props to HTML attributes.
  2. Small fixes to some bugs in the actual test framework, including
    1. a reset of modules in between server and client render to reset dev errors, and
    2. testing to make sure that the client render didn't blow away the server-rendered DOM elements.

As always, any feedback is welcome. Thanks!

@aickin
Copy link
Contributor Author

aickin commented Mar 9, 2017

@spicyj, could you help me find a reviewer for this? I have probably four more PRs of unit tests behind it, so I'd love to see if we could find a way to move this one along.

And as always, I'm open to suggestions of how to make the PRs more digestible. Thanks!

@ptomasroos
Copy link

This is just great! Would look forward to have improved tests for SSR in the code base!

@@ -61,14 +61,18 @@ function renderIntoDom(reactElement, domElement, errorCount = 0) {
);
}

async function renderIntoString(reactElement, errorCount = 0) {
return await expectErrors(
() => new Promise(resolve => resolve(ReactDOMServer.renderToString(reactElement))),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there an issue with Promise.resolve?

Copy link
Contributor Author

@aickin aickin Mar 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it behaves differently if renderToString throws an error. With Promise.resolve(), the arrow function throws, whereas with new Promise, the promise just rejects. There are some tests that I haven't yet submitted that depend on the promises rejecting on error rather than throwing up the call stack.


// this seems like somewhat odd behavior, as it isn't how <a html> works
// in HTML, but it's existing behavior.
itRenders('string prop with true value', async render => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This test is probably unnecessary since it's seen the same by React as href: true and I'm sure we'll be careful about compat if we ever change JSX.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally fair point. I'll remove it.


// this does not seem like correct behavior, since hidden="" in HTML indicates
// that the boolean property is present. however, it is how the current code
// behaves, so the test is included here.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL!

@aickin
Copy link
Contributor Author

aickin commented Mar 19, 2017

This has been approved and passed CI (and then failed after the move to prettier, but I just fixed that, too). @spicyj, would it be possible to merge? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants