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 complete unit tests for utils interface #5

Merged
merged 1 commit into from
Oct 23, 2017
Merged

Add complete unit tests for utils interface #5

merged 1 commit into from
Oct 23, 2017

Conversation

pgoldrbx
Copy link
Contributor

This PR adds all missing test for the utils methods. I have tried to be strict while adhering to the existing test style as much as possible.

NOTE: These tests raise at least one bug and some other outstanding questions.

⚠️ The method isRaw is called by appendChild but is not defined.

Failing tests are commented and skipped for the moment.

];
utils.appendChild(jml, fragment);
assert.deepEqual(fragment, []);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this test when I realized the fragment was being muted (by calling child.shift()). I wasn't sure if this was intentional. Personally, I would argue that functions should be pure whenever possible and that the child param should not be mutated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Owner

Choose a reason for hiding this comment

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

Yep, we had better to make function pure, and you can fix it in next PR, thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filed: #7
Patch: #8

const child = new function RawChild() {};
utils.appendChild(jml, child);
assert.strictEqual(jml, ['div', child]);
});
Copy link
Contributor Author

@pgoldrbx pgoldrbx Oct 21, 2017

Choose a reason for hiding this comment

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

This test highlights a bug. The isRaw method is not defined. Furthermore, I'm not sure what it was intended to do. Based on some research, it would seem to be in html.js but I'm not entirely certain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Owner

Choose a reason for hiding this comment

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

Just raise a new issue, I need to to read the source code, and may be re-design these APIs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Issue #9
PR #10

const attrs = { a: 1 };
utils.appendChild(jml, attrs);
assert.deepEqual(jml, ['div', { a: 1 }]);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This also fails but it is due to the error above. The isRaw call happens before the method can reach this logic.

Copy link
Owner

Choose a reason for hiding this comment

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

Just raise a new issue, I need to to read the source code, and may be re-design these APIs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also fixed by #10


utils.appendChild(jml, 'z');
assert.deepEqual(jml, ['', 'xz']);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this test based on the condition to allow a parent element with no length. I'm not really sure what the purpose is. To build a fragment?

Copy link
Owner

Choose a reason for hiding this comment

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

Just raise a new issue, I need to to read the source code, and may be re-design these APIs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filed issue: #11

@pgoldrbx pgoldrbx mentioned this pull request Oct 21, 2017
@benjycui benjycui merged commit b9a2193 into benjycui:master Oct 23, 2017
@pgoldrbx pgoldrbx deleted the test/utils branch October 23, 2017 15:02
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