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: README.md
+212-2Lines changed: 212 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,7 @@ This is still early days for the library and nothing is set in stone with regard
12
12
If you have an idea, suggestion, or bug, please add an [issue](issues). Pull-requests are also very welcome.
13
13
14
14
## Getting started
15
+
1. Create the necessary projects (Razor Class Library and xUnit class Library). See the [sample project](master/sample) for an example.
15
16
1. Install the [Razor.Components.Testing.Library](https://www.nuget.org/packages/Razor.Components.Testing.Library) library from Nuget into your xUnit test project.
16
17
2. Optionally, add an `_Imports.razor` to test project to avoid typing using and inherits statements in each test files.
17
18
3. Write `.razor`-based tests.
@@ -29,6 +30,215 @@ If you have an idea, suggestion, or bug, please add an [issue](issues). Pull-req
29
30
```
30
31
31
32
## Example
32
-
The test examples below tests the Bootstrap [`Alert`](sample/ComponentLib/Alert.razor) sample componentfound in the sample folder:
33
+
The test examples below tests the Bootstrap [`Alert.razor`](sample/ComponentLib/Alert.razor) sample component, using the [`AlertTests.razor`](sample/RazorComponentLibTests/AlertTests.razor), both found in the sample folder.
To perform a simple comparison test between the HTML generated by the `<Alert />` component, add a `<Fact />` component to your `.razor`-test-file, include the `<TestSetup>` component, that should contain the setup of the component under test, and an `<ExpectedHtml/>` component that contains the expected output.
97
+
98
+
E.g.:
99
+
100
+
```
101
+
<Fact DisplayName="Alert renders as empty without child content">
102
+
<TestSetup>
103
+
<Alert />
104
+
</TestSetup>
105
+
<ExpectedHtml>
106
+
<div class="alert fade show" role="alert"></div>
107
+
</ExpectedHtml>
108
+
</Fact>
109
+
110
+
<Fact DisplayName="Alert renders with child content if provided">
111
+
<TestSetup>
112
+
<Alert>FOO BAR BAZ</Alert>
113
+
</TestSetup>
114
+
<ExpectedHtml>
115
+
<div class="alert fade show" role="alert">FOO BAR BAZ</div>
116
+
</ExpectedHtml>
117
+
</Fact>
118
+
119
+
<Fact DisplayName="Alert adds color when specified">
120
+
<TestSetup>
121
+
<Alert Color="primary" />
122
+
</TestSetup>
123
+
<ExpectedHtml>
124
+
<div class="alert fade show alert-primary" role="alert"></div>
125
+
</ExpectedHtml>
126
+
</Fact>
127
+
128
+
<Fact DisplayName="Providing a role overrides default role value">
0 commit comments