-
Notifications
You must be signed in to change notification settings - Fork 79
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
Dojo Test Renderer #710
Dojo Test Renderer #710
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit ae31cbd:
|
h.trigger('@button', 'onClick'); | ||
const r = renderer(() => <Action fetchItems={fetchItems} />); | ||
r.expect(template); | ||
r.property(WrappedButton, 'onClick'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth mentioning in the documentation below how the onClick
property is found in the renderer using the wrapped button. It's not immediately clear how the property
method is using the WrappedButton
to find the real Button
on the rendered widget when the rendered widget isn't constructed using the wrapped widgets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems reasonable, I'll add something into the supplemental docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@devpaul I have added:
The test renderer uses the location of a wrapped test node in the expected tree to attempt to perform the requested action (either
r.property()
orr.child()
) on the actual output of the widget under test. If the wrapped test node does not match the corresponding node in the actual output tree then no action will be performed and the assertion will report a failure.
To the Wrapped Test Nodes
section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this. It'll be a good reference!
What happens if a wrapped widget is used more than once? const WrappedButton = wrap(Button);
const template = assertionTemplate(() => (
<div classes={[css.root]}>
<WrappedButton key="button1" onClick={() => {}}>
Fetch
</WrappedButton>
<WrappedButton key="button2" onClick={() => {}}>
Fetch
</WrappedButton>
</div>
));
const r = renderer(() => <MyWidget buttonActions={[ jest.fn(), jest.fn() ]} />);
r.expect(template);
r.property(WrappedButton, 'onClick'); Let's say that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very minor suggestions (reviewed the docs more than the code)... I assume someone else is reviewing the code here.
@devpaul at the moment it would actually call the corresponding |
15b0d1d
to
c344242
Compare
Codecov Report
@@ Coverage Diff @@
## master #710 +/- ##
==========================================
- Coverage 97.78% 97.72% -0.06%
==========================================
Files 121 125 +4
Lines 7050 7485 +435
Branches 1603 1718 +115
==========================================
+ Hits 6894 7315 +421
- Misses 156 170 +14
Continue to review full report at Codecov.
|
Sounds like it would be reasonable to throw an exception and fail the test at this point. It would give us a chance to provide a good error message that educates the user on proper usage. If we proceed there's a chance that it might work for their test (i.e. maybe they only check the first value). |
@devpaul the test renderer will now throw an error if the same wrapped test node is detected multiple times during an assertion |
docs/en/testing/supplemental.md
Outdated
- `renderFunction`: A function that returns a `WNode` for the widget under test | ||
- [`customComparators`](/learn/testing/dojo-test-harness#custom-comparators): Array of custom comparator descriptors. Each provides a comparator function to be used during the comparison for `properties` located using a `selector` and `property` name | ||
- `options`: Expanded options for the harness which includes `customComparators` and an array of middleware/mocks tuples. | ||
The test renderer uses the location of a wrapped test node in the expected tree to attempt to perform the requested action (either `r.property()` or `r.child()`) on the actual output of the widget under test. If the wrapped test node does not match the corresponding node in the actual output tree then no action will be performed and the assertion will report a failure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this statement is made out of context here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maier49 It's trying to explain how the wrapped nodes are used, is there a more appropriate place outside of the test node section?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
docs/en/testing/supplemental.md
Outdated
|
||
## Harness API | ||
Working with [assertion templates](/missing/link) and the test renderer is done using [wrapped test nodes](/missing/link) that are defined in the assertion templates structure, ensuring type safety throughout the testing life-cycle. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these links coming in later PRs?
|
||
Given the following VDOM structure: | ||
In addition to asserting the output from a widget, widget behavior can be tested by using the `renderer.property()` function. The `property()` function takes a [wrapped test node]() and the key of a property to call before the next call to `expect()`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can take additional arguments to pass to the function still right? Maybe worth mentioning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
Co-Authored-By: Bradley Maier <brdlmaier49@gmail.com>
Type: feature
The following has been addressed in the PR:
prettier
as per the readme code style guidelinesDescription:
Introduces a new testing module,
@dojo/framework/testing/renderer
, intended to retire the existing@dojo/framework/testing/harness
, theharness
has been deprecated but not removed.The existing
harness
is has been moved to theframework/testing/harness
folder.Features:
harness
API to promote testing best practices (removedexpectPartial
andgetRender
).compare
function in combination with a wrapped testing nodetsx
format overv()
andw()
Note: Testing render props is not possible with the new test renderer and recommended to migrate these widgets to use functional children for full test renderer support.
Resolves #535
Resolves #529