You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document describes the changes that need to be made to migrate from bUnit 1.x to 2.x.
3
+
4
+
## Removal of `GetChangesSinceFirstRender` and `GetChangesSinceLastRender` methods
5
+
The `GetChangesSinceFirstRender` and `GetChangesSinceLastRender` methods have been removed from `IRenderedComponent<TComponent>`. There is no one-to-one replacement for these methods, but the general idea is to select the HTML in question via `Find` and assert against that.
6
+
7
+
Alternatively, the `IRenderFragment` still offers the `OnMarkupUpdated` event, which can be used to assert against the markup after a render.
Copy file name to clipboardExpand all lines: docs/site/docs/verification/verify-markup.md
+1-50Lines changed: 1 addition & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -120,55 +120,6 @@ The semantic HTML comparer can be customized to make a test case even more stabl
120
120
121
121
Learn more about the customization options on the <xref:semantic-html-comparison> page.
122
122
123
-
## Finding expected differences
124
-
125
-
It can sometimes be easier to verify that an expected change, and only that change, has occurred in the rendered markup than it can be to specify how all the rendered markup should look after re-rendering.
126
-
127
-
bUnit comes with a number of ways for finding lists of `IDiff`; the representation of a difference between two HTML fragments. All of these are direct methods or extension methods on the <xref:Bunit.IRenderedFragment> type or on the `INode` or `INodeList` types:
128
-
129
-
-<xref:Bunit.IRenderedFragment.GetChangesSinceFirstRender> method on <xref:Bunit.IRenderedFragment>. This method returns a list of differences since the initial first render of a component.
130
-
-<xref:Bunit.IRenderedFragment.GetChangesSinceSnapshot> and <xref:Bunit.IRenderedFragment.SaveSnapshot> methods on <xref:Bunit.IRenderedFragment>. These two methods combined make it possible to get a list of differences between the last time the <xref:Bunit.IRenderedFragment.SaveSnapshot> method was called and the time a call to the <xref:Bunit.IRenderedFragment.GetChangesSinceSnapshot> method is placed.
131
-
-`CompareTo()` methods from <xref:Bunit.CompareToExtensions> for the <xref:Bunit.IRenderedFragment>, `INode`, and `INodeList` types. These methods return a list of differences between the two input HTML fragments.
132
-
133
-
In addition to this, there are a number of experimental assertion helpers for `IDiff` and `IEnumerable<IDiff>`, making it easier and more concise to declare your assertions.
134
-
135
-
Let's look at a few examples of using the assertion helpers. In the first one, we will use the `<Counter>` component listed below:
- On line 8, <xref:Bunit.IRenderedFragment.GetChangesSinceFirstRender> is used to get a list of differences.
146
-
- On line 11, the `ShouldHaveSingleChange()` method is used to verify that there is only one change found.
147
-
- On line 14, the `ShouldBeTextChange()` method is used to verify that the single `IDiff` is a text change.
148
-
149
-
Testing a more **complex life cycle of a component** can be done more easily using the <xref:Bunit.IRenderedFragment.GetChangesSinceSnapshot> and <xref:Bunit.IRenderedFragment.SaveSnapshot> methods along with a host of other assert helpers.
150
-
151
-
This example tests the `<CheckList>` component listed below. The component allows you to add new items to the checklist by typing into the input field and hitting the `enter` key. Items can be removed from the list again by clicking on them.
1. First the component is rendered and the input field is found.
162
-
2. The first item is added through the input field.
163
-
3. The <xref:Bunit.IRenderedFragment.GetChangesSinceFirstRender>, `ShouldHaveSingleChange()` and `ShouldBeAddition()` methods are used to verify that the item was correctly added.
164
-
4. The <xref:Bunit.IRenderedFragment.SaveSnapshot> is used to save a snapshot of current DOM nodes internally in the `cut`. This reduces the number of diffs found in the following steps, simplifying verification.
165
-
5. A second item is added to the check list.
166
-
6. Two verifications are performed at this point, one using the <xref:Bunit.IRenderedFragment.GetChangesSinceFirstRender> method which finds two changes, and one using the <xref:Bunit.IRenderedFragment.GetChangesSinceSnapshot> method, which finds a single change. The first is only done for illustrative purposes.
167
-
7. A new snapshot is saved, replacing the previous one with another call to the <xref:Bunit.IRenderedFragment.SaveSnapshot> method.
168
-
8. Finally the last item in the list is found and clicked, and the <xref:Bunit.IRenderedFragment.GetChangesSinceSnapshot> method is used to find the changes, a single diff, which is verified as a removal of the second item.
169
-
170
-
As mentioned earlier, the `IDiff` assertion helpers are still experimental. Any feedback and suggestions for improvements should be directed to the [related issue](https://github.com/egil/bUnit/issues/84) on GitHub.
171
-
172
123
## Verification of raw markup
173
124
174
125
To access the rendered markup of a component, just use the <xref:Bunit.IRenderedFragment.Markup> property on <xref:Bunit.IRenderedFragment>. This holds the *raw* HTML from the component as a `string`.
@@ -182,4 +133,4 @@ To get the markup as a string, do the following:
0 commit comments