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

Reorganize and improve render unit tests #1199

Merged
merged 9 commits into from Aug 29, 2018

Conversation

andrewiggins
Copy link
Member

Reorganize render unit tests to better represent the expectations that the test are validating. Also, improved a couple tests to better cover their scenario.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 447f08d on andrewiggins:improve-render-uts into cb67a81 on developit:master.

Copy link
Member Author

@andrewiggins andrewiggins left a comment

Choose a reason for hiding this comment

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

I found this PR to be slightly easier to review with the "No Whitespace" option turned on since some of these changes are just indentation changes.

@@ -151,12 +151,6 @@ describe('Components', () => {
expect(scratch.innerHTML).to.equal('');
});

// Test for #651
it('should set enumerable boolean attribute', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

I just moved this into the render.js UT file since this test doesn't actually use an components

});
});

describe('event handling', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

I grouped all event handling under a common describe block

Copy link
Member Author

Choose a reason for hiding this comment

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

I also broke up the event handling tests to better specify the various concerns they were testing

Copy link
Member

Choose a reason for hiding this comment

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

Yay, meaningful failure messages!

.that.matches(/top\s*:\s*5px\s*/)
.and.matches(/position\s*:\s*relative\s*/);
});
describe('style attribute', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved all style tests under a common describe block

}
render(props, { html }) {
return html ? <div dangerouslySetInnerHTML={{ __html: html }} /> : <div />;
describe('dangerouslySetInnerHTML', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Group all dangerouslySetInnerHTML tests under a common describe block

{ todos.map( todo => (<div>{todo.text}</div> )) }
<div onKeyDown={this.addTodo}>
{ todos.map( todo => ([
<span>{todo.text}</span>,
Copy link
Member Author

Choose a reason for hiding this comment

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

The original issue called out this example as a better test for this test case so I updated the test to cover this.

it('should only register on* functions as handlers', () => {
let click = () => {},
onclick = () => {};
it('should properly switch from string styles to object styles and back', () => {
Copy link
Member

Choose a reason for hiding this comment

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

we'll want to revisit this if we decide to remove string style support (it's a preact-only feature)

});
});

describe('event handling', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Yay, meaningful failure messages!

@@ -588,44 +699,69 @@ describe('render()', () => {
expect(sortAttributes(html)).to.equal(sortAttributes('<input type="range" min="0" max="100" list="steplist">'));
});

it('should not execute append operation when child is at last', (done) => {
it('should not execute append operation when child is at last', () => {
// See developit/preact#717 for discussion about the issue this addresses
Copy link
Member

Choose a reason for hiding this comment

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

👍 I wish I'd left more of these issue references around.

Copy link
Member

Choose a reason for hiding this comment

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

side note: we should totally look into reusing this component + plumbing for a bunch of different tests.

@developit
Copy link
Member

Approved x1000

@developit developit merged commit 30c0fd7 into preactjs:master Aug 29, 2018
@andrewiggins andrewiggins deleted the improve-render-uts branch August 29, 2018 02:21
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.

None yet

3 participants