Skip to content

Commit 24785d3

Browse files
committed
Added example to home and tweaks to other pages
1 parent 0478d30 commit 24785d3

6 files changed

Lines changed: 54 additions & 23 deletions

File tree

docs/docs/getting-started/writing-csharp-tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Rendering a component happens through bUnit's <xref:Bunit.TestContext>, and the
1515

1616
Lets see a simple example, where we test the following `<HelloWorld>` component:
1717

18-
[!code-cshtml[HelloWorld.razor](../../samples/components/HelloWorld.razor)]
18+
[!code-html[HelloWorld.razor](../../samples/components/HelloWorld.razor)]
1919

2020
# [xUnit](#tab/xunit)
2121

docs/docs/getting-started/writing-razor-tests.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---
1+
---
22
uid: writing-razor-tests
33
title: Writing tests in Razor syntax for Blazor components
44
---
@@ -29,7 +29,7 @@ A Blazor test component is conceptually very similar to a regular test class in
2929

3030
Besides that, Blazor test components has to inherit from <xref:Bunit.TestComponentBase>, e.g.:
3131

32-
[!code-html[HelloWorldTest.razor](../../samples/tests/razor/HelloWorldTest.razor#L1)]
32+
[!code-html[](../../samples/tests/razor/HelloWorldTest.razor#L1)]
3333

3434
The following two sections will show how to create tests using bUnit's <xref:Bunit.Fixture> and <xref:Bunit.SnapshotTest> components.
3535

docs/docs/toc.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
## [Fixture test options](xref:fixture-options)
66
## [SnapshotTest options](xref:snapshot-options)
77

8-
# [Providing input](xref:passing-parameters-to-components)
8+
# [Providing input](xref:providing-input)
99
## [Parameters and cascading values](xref:passing-parameters-to-components)
1010
## [Inject services](xref:inject-services-into-components)
1111
## [Trigger event handlers](xref:trigger-event-handlers)
1212
## [Trigger renders](xref:trigger-renders)
1313
## [Configure 3rd party libraries](xref:configure-3rd-party-libs)
1414

15-
# [Verifying output](xref:verify-markup)
15+
# [Verifying output](xref:verifying-output)
1616
## [Verify markup](xref:verify-markup)
1717
## [Verify component state](xref:verify-component-state)
1818
## [Semantic HTML markup comparison](xref:semantic-html-comparison)

docs/index.md

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,22 @@ The library builds on top of existing unit testing frameworks such as xUnit, whi
2626

2727
The library's goal is to make it easy to write _comprehensive, stable unit tests_ for Blazor Components/Razor Components.
2828

29-
For example, to test the [`Counter.razor`](https://github.com/egil/bunit/blob/master/sample/src/Pages/Counter.razor) component that is part of the Blazor "file-new-project" project, you can do the following, using bUnit and xUnit:
30-
31-
```csharp
32-
[Fact]
33-
public void CounterShouldIncrementWhenClicked()
34-
{
35-
// Arrange: render the Counter.razor component
36-
var cut = RenderComponent<Counter>();
37-
38-
// Act: find and click the <button> element to increment
39-
// the counter in the <p> element
40-
cut.Find("button").Click();
41-
42-
// Assert: first find the <p> element, then verify its content
43-
cut.Find("p").MarkupMatches("<p>Current count: 1</p>");
44-
}
45-
```
46-
4729
**Go to [Documentation](xref:getting-started) to learn more.**
4830

4931
> [!NOTE]
5032
> The documentation is currently being rewritten to reflect the recent changes. Please excuse the mess.
5133
34+
### Simple example
35+
36+
For example, to test the `<Counter>` component listed below:
37+
38+
[!code-html[Counter.razor](./samples/components/Counter.razor)]
39+
40+
You can do the following, using bUnit and xUnit:
41+
42+
[!code-csharp[CounterTest.cs](./samples/tests/xunit/CounterTest.cs#L8-L20)]
43+
44+
**Go to [Documentation](xref:getting-started) to learn more.**
5245

5346
### NuGet downloads
5447

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<h1>Counter</h1>
2+
3+
<p>
4+
Current count: @currentCount
5+
</p>
6+
7+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
8+
9+
@code {
10+
int currentCount = 0;
11+
12+
void IncrementCount()
13+
{
14+
currentCount++;
15+
}
16+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Xunit;
2+
using Bunit;
3+
4+
namespace Docs.Components.Xunit
5+
{
6+
public class CounterTest : TestContext
7+
{
8+
[Fact]
9+
public void CounterShouldIncrementWhenClicked()
10+
{
11+
// Arrange: render the Counter.razor component
12+
var cut = RenderComponent<Counter>();
13+
14+
// Act: find and click the <button> element to increment
15+
// the counter in the <p> element
16+
cut.Find("button").Click();
17+
18+
// Assert: first find the <p> element, then verify its content
19+
cut.Find("p").MarkupMatches("<p>Current count: 1</p>");
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)