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
Copy file name to clipboardExpand all lines: docs/razor-examples.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# Writing Blazor Component tests in a mix of Razor and C# code
2
2
3
-
The library supports specifying the component under test and other markup/fragments using Razor syntax. The advantage is that we get Visual Studio help writing Razor and HTML, which is a much nicer experience than writing HTML in a string in a C# class/file. This is especially useful for more complex scenarios, where e.g. a component under test has many parameters or complex child contents.
3
+
The library supports specifying the component under test and other markup/fragments using Razor syntax. The advantage is that we get Visual Studio's help writing Razor and HTML with IntelliSense and auto complete, which is a much nicer experience than writing HTML in a string in a C# class/file. This is especially useful for more complex scenarios, where e.g. a component under test has many parameters or complex child contents.
4
4
5
-
**NOTE:** This feature is _EXPERIMENTAL_ and syntax and API will likely changed. See [Contribute](readme.md/#contribute) for info on how to provide feedback and suggestions.
5
+
**NOTE:** This feature is _EXPERIMENTAL_, and syntax and API will likely be changed. See [Contribute](readme.md/#contribute) for info on how to provide feedback and suggestions.
6
6
7
7
1.[Creating new test component](#creating-new-test-component)
8
8
2.[Defining test cases](#defining-test-cases)
@@ -25,13 +25,13 @@ You will also need to import a few namespaces to make asserting and mocking poss
25
25
@using Xunit @*or e.g. Shouldly*@
26
26
```
27
27
28
-
**Tip:** In the folder you keep your Razor-based tests, add a `_Imports.razor` file, and put the above into that. Then all test components inherits the correct base component by default and have the default imports available.
28
+
**Tip:** In the folder you keep your Razor-based tests, add a `_Imports.razor` file, and put the above into that. Then all test components inherit the correct base component by default and have the default imports available.
29
29
30
30
## Defining test cases
31
31
32
-
When you have a Razor test component created, its time to add test cases. This is done via the `<Fixture>` component and related test methods and child components.
32
+
When you have a Razor test component created, it's time to add test cases. This is done via the `<Fixture>` component and related test methods and child components.
33
33
34
-
Lets look at what options we have by setting up an empty test case, first the code:
34
+
Let's look at what options we have by setting up an empty test case, first the code:
35
35
36
36
```cshtml
37
37
<Fixture Setup="Setup"
@@ -75,7 +75,7 @@ The code above works as follows:
75
75
- It is inside child component `<ComponentUnderTest>` where you declare the component under test.
76
76
- Any markup or component fragments that is needed for the test can be declared inside the optional `<Fragment>` components. The `Id` parameter is optional, and only needed if you have more than one.
77
77
78
-
- To render and get the component under test or any of the fragments, use the `GetComponentUnderTest<TComponent>()` method on the `IRazorTestContext` object. `GetFragment()` can be called both with and without a `TComponent`, e.g. if its just markup defined in it.
78
+
- To render and get the component under test or any of the fragments, use the `GetComponentUnderTest<TComponent>()` method on the `IRazorTestContext` object. `GetFragment()` can be called both with and without a `TComponent`, e.g. if it's just markup defined in it.
79
79
80
80
- Inside the `Test` methods you can do all the things you can in C#-based tests, e.g. assert against the CUT. The only difference is that some methods such as `TakeSnapshot()` is not available on the local scope, but through the `IRazorTestContext` object passed to each Test method.
81
81
@@ -128,9 +128,9 @@ This example shows how [ThemedElement.razor](../sample/src/Components/ThemedElem
128
128
}
129
129
```
130
130
131
-
This example shows how [ThemedButton.razor](../sample/src/Components/ThemedButton.razor) can be tested with with child content, and how a `<Fragment>` can be used to specify the expected output.
131
+
This example shows how [ThemedButton.razor](../sample/src/Components/ThemedButton.razor) can be tested with child content, and how a `<Fragment>` can be used to specify the expected output.
132
132
133
-
Lets look at a more complex example, a test of the [TodoList.razor](../sample/src/Pages/TodoList.razor) component:
133
+
Let's look at a more complex example, a test of the [TodoList.razor](../sample/src/Pages/TodoList.razor) component:
0 commit comments