Skip to content

Commit f0e030b

Browse files
committed
Spelling and gramma changes from Packt editor
1 parent 776a8c0 commit f0e030b

File tree

6 files changed

+21
-21
lines changed

6 files changed

+21
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
- Pass parameters, cascading values and inject services into components under test
1616
- Mock `IJSRuntime`, Blazor authentication and authorization, and others
1717

18-
bUnit builds on top of existing unit testing frameworks such as xUnit, NUnit, and MSTest, which run the Blazor components tests in just the same way as any normal unit test. bUnit runs a test in milliseconds, compared to browser-based UI tests which usually take seconds to run.
18+
bUnit builds on top of existing unit testing frameworks such as xUnit, NUnit, and MSTest, which run the Blazor component tests in just the same way as any normal unit test. bUnit runs a test in milliseconds, compared to browser-based UI tests which usually take seconds to run.
1919

2020
**Go to [bUnit.egilhansen.com](https://bunit.egilhansen.com) to learn more.**
2121

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@ Use **bUnit** to render the component under test, pass in its parameters, inject
1212
Rendering a component happens through bUnit's <xref:Bunit.TestContext>. The result of the rendering is an `IRenderedComponent`, referred to as a "rendered component", that provides access to the component instance and the markup produced by the component.
1313

1414
> [!NOTE]
15-
> The preview and beta versions of bUnit included an experimental feature for writing tests using two test components, `<Fixture>` and `<SnapshotTest>`. Since there is now a better way to write tests in `.razor` files, the old experimental feature has been moved into a separate project named `bunit.web.testcomponents`. It is kept around to not break early adopters, but _no additional features or improvements_ is planned to it.
15+
> The preview and beta versions of bUnit included an experimental feature for writing tests using two test components, `<Fixture>` and `<SnapshotTest>`. Since there is now a better way to write tests in `.razor` files, the old experimental feature has been moved into a separate project named `bunit.web.testcomponents`. It is kept around to not break early adopters, but _no additional features or improvements_ are planned to it.
1616
>
1717
> To learn more, head over to the [bunit.web.testcomponents project](https://github.com/egil/bUnit/tree/main/src/bunit.web.testcomponents) on GitHub.
1818
1919
## Write tests in `.cs` or `.razor` files
2020

2121
bUnit works with MSTest, NUnit, and xUnit, and it allows you to write the unit tests in either `.cs` or `.razor` files.
2222

23-
The latter, writing tests in `.razor` files, provides an easier way to declare component- and HTML-markup in the tests, so it will most likely be the go to for many people in the future.
23+
The latter, writing tests in `.razor` files, provides an easier way to declare component markup and HTML markup in the tests, so it will most likely be the go-to for many people in the future.
2424

2525
*However*, the current Razor editor in Visual Studio 2019 does not offer all the code editing features available in the C# editor, and has some formatting bugs on top of that, so that is something to consider if you choose to write tests in `.razor` files.
2626

27-
The following sections will show how to get started writing tests in either `.cs` or `.razor` files.
27+
The following sections show how to get started writing tests in either `.cs` or `.razor` files.
2828

2929
## Creating basic tests in `.razor` files
3030

3131
Before writing tests in `.razor` files, a few things needs to be in place:
3232

3333
1. Make sure the test project has the SDK type set to `Microsoft.NET.Sdk.Razor`. Otherwise the Blazor compiler will not translate your `.razor` files into runnable code.
34-
2. Add a `_Imports.razor` file to the test project. It serves the same purpose as `_Imports.razor` files in regular Blazor projects. These using statements are useful to add right away:
34+
2. Add an `_Imports.razor` file to the test project. It serves the same purpose as `_Imports.razor` files in regular Blazor projects. These using statements are useful to add right away:
3535

3636
```cshtml
3737
@using Microsoft.AspNetCore.Components.Forms
@@ -43,7 +43,7 @@ Before writing tests in `.razor` files, a few things needs to be in place:
4343
@using Bunit.TestDoubles
4444
```
4545

46-
Also add a using statement for your general purpose testing framework, e.g. `@using Xunit` for xUnit.
46+
Also add an using statement for your general purpose testing framework, e.g. `@using Xunit` for xUnit.
4747

4848
With that in place, lets look at a simple example that tests the following `<HelloWorld>` component:
4949

@@ -71,7 +71,7 @@ With that in place, lets look at a simple example that tests the following `<Hel
7171

7272
The test above does the following:
7373

74-
1. Creates a new instance of the disposable bUnit <xref:Bunit.TestContext>, and assigns it to `ctx` variable using the `using var` syntax to avoid unnecessary source code indention.
74+
1. Creates a new instance of the disposable bUnit <xref:Bunit.TestContext>, and assigns it to `ctx` the variable using the `using var` syntax to avoid unnecessary source code indention.
7575
2. Renders the `<HelloWorld>` component using <xref:Bunit.TestContext>, which is done through the <xref:Bunit.TestContext.Render(Microsoft.AspNetCore.Components.RenderFragment)> method. We cover passing parameters to components on the <xref:passing-parameters-to-components> page.
7676
3. Verifies the rendered markup from the `<HelloWorld>` component using the `MarkupMatches` method. The `MarkupMatches` method performs a semantic comparison of the expected markup with the rendered markup.
7777

@@ -83,7 +83,7 @@ The test above does the following:
8383
8484
### Secret sauce of '.razor' files tests
8585

86-
The trick employed in these tests is the "[inline Razor templates syntax](https://docs.microsoft.com/en-us/aspnet/core/blazor/components/?view=aspnetcore-5.0#razor-templates)", i.e. where a render fragment is simply created using the `@<{HTML tag}>...</{HTML tag}>` notation. In that notation there is no need to do any escaping of e.g. the quatation mark (`"`), that is usually associated with working with markup in C# code.
86+
The trick employed in these tests is the "[inline Razor templates syntax](https://docs.microsoft.com/en-us/aspnet/core/blazor/components/?view=aspnetcore-5.0#razor-templates)", i.e. where a render fragment is simply created using the `@<{HTML tag}>...</{HTML tag}>` notation. In that notation there is no need to do any escaping of e.g. the quotation mark (`"`), that is usually associated with working with markup in C# code.
8787

8888
One small caveat to be aware of is that the inline Razor templates syntax only supports one outer element, e.g. this is OK:
8989

@@ -102,7 +102,7 @@ However, this will **not** work:
102102
<Bar></Bar>
103103
```
104104

105-
There is a simple workaround though. Wrap all elements in the special Blazor element `<text>`. The `<text>` element will not be part of the rendered output, but is provides a simple way to group multiple root elements into a single inline Razor templates. E.g.:
105+
There is a simple workaround though: wrap all elements in the special Blazor element `<text>`. The `<text>` element will not be part of the rendered output, but it provides a simple way to group multiple root elements into a single inline Razor template. E.g.:
106106

107107
```cshtml
108108
@<text>
@@ -113,7 +113,7 @@ There is a simple workaround though. Wrap all elements in the special Blazor ele
113113

114114
### Remove boilerplate code from tests
115115

116-
We can remove some boilerplate code from each test by making the <xref:Bunit.TestContext> implicitly available to the test class, so we don't have to have `using var ctx = new Bunit.TestContext();` in every test. This can be done like this:
116+
We can remove some boilerplate code from each test by making the <xref:Bunit.TestContext> implicitly available to the test class, so we don't have to have `using var ctx = new Bunit.TestContext();` in every test. This can be done like so:
117117

118118
# [xUnit](#tab/xunit)
119119

@@ -146,7 +146,7 @@ Then methods like <xref:Bunit.TestContext.Render(Microsoft.AspNetCore.Components
146146
> [!IMPORTANT]
147147
> All the examples in the documentation explicitly new up a `TestContext`, i.e. `using var ctx = new TestContext()`. If you are using the trick above and have your test class inherit from `TestContext`, you should **NOT** new up a `TestContext` in test methods also.
148148
>
149-
> Simply call the test contest's methods directly, as they are available in your test class.
149+
> Simply call the test context's methods directly, as they are available in your test class.
150150
>
151151
> For example, `var cut = ctx.Render(@<HelloWorld/>);`
152152
> becomes `var cut = Render(@<HelloWorld/>);`.
@@ -180,7 +180,7 @@ This is a simple example of writing tests in `.cs` files which tests the followi
180180

181181
The test above does the following:
182182

183-
1. Creates a new instance of the disposable bUnit <xref:Bunit.TestContext>, and assigns it to `ctx` variable using the `using var` syntax to avoid unnecessary source code indention.
183+
1. Creates a new instance of the disposable bUnit <xref:Bunit.TestContext>, and assigns it to the `ctx` variable using the `using var` syntax to avoid unnecessary source code indention.
184184
2. Renders the `<HelloWorld>` component using <xref:Bunit.TestContext>, which is done through the <xref:Bunit.TestContext.RenderComponent``1(System.Action{Bunit.ComponentParameterCollectionBuilder{``0}})> method. We cover passing parameters to components on the <xref:passing-parameters-to-components> page.
185185
3. Verifies the rendered markup from the `<HelloWorld>` component using the `MarkupMatches` method. The `MarkupMatches` method performs a semantic comparison of the expected markup with the rendered markup.
186186

@@ -192,7 +192,7 @@ The test above does the following:
192192
193193
### Remove boilerplate code from tests
194194

195-
We can remove some boilerplate code from each test by making the <xref:Bunit.TestContext> implicitly available to the test class, so we don't have to have `using var ctx = new Bunit.TestContext();` in every test. This can be done like this:
195+
We can remove some boilerplate code from each test by making the <xref:Bunit.TestContext> implicitly available to the test class, so we don't have to have `using var ctx = new Bunit.TestContext();` in every test. This can be done like so:
196196

197197
# [xUnit](#tab/xunit)
198198

@@ -206,7 +206,7 @@ Since xUnit instantiates test classes for each execution of the test methods ins
206206

207207
[!code-csharp[BunitTestContext.cs](../../../samples/tests/nunit/BunitTestContext.cs)]
208208

209-
Since NUnit instantiates a test class only once for all tests inside it, we cannot simply inherit directly from <xref:Bunit.TestContext> as we want a fresh instance of <xref:Bunit.TestContext> for each test. Instead, we create a helper class, `BunitTestContext`, listed above, and use that to hook into NUnit's `[SetUp]` and `[TearDown]` methods, which runs before and after each test.
209+
Since NUnit instantiates a test class only once for all tests inside it, we cannot simply inherit directly from <xref:Bunit.TestContext> as we want a fresh instance of <xref:Bunit.TestContext> for each test. Instead, we create a helper class, `BunitTestContext`, listed above, and use that to hook into NUnit's `[SetUp]` and `[TearDown]` methods, which run before and after each test.
210210

211211
Then methods like <xref:Bunit.TestContext.RenderComponent``1(System.Action{Bunit.ComponentParameterCollectionBuilder{``0}})> can be called directly from each test, as seen in the listing above.
212212

@@ -223,7 +223,7 @@ Then methods like <xref:Bunit.TestContext.RenderComponent``1(System.Action{Bunit
223223
***
224224

225225
> [!IMPORTANT]
226-
> All the examples in the documentation explicitly new up a `TestContext`, i.e. `using var ctx = new TestContext()`. If you are using the trick above and have your test class inherit from `TestContext`, you should **NOT** new up a `TestContext` in test methods also.
226+
> All the examples in the documentation explicitly new up a `TestContext`, i.e. `using var ctx = new TestContext()`. If you are using the trick above and have your test class inherit from `TestContext`, you should **NOT** new up another `TestContext` in test methods also.
227227
>
228228
> Simply call the test contest's methods directly, as they are available in your test class.
229229
>
@@ -232,7 +232,7 @@ Then methods like <xref:Bunit.TestContext.RenderComponent``1(System.Action{Bunit
232232
233233
## Further reading
234234

235-
With the basics out of the way, next we will look at how to pass parameters and inject services into our component under test. After that, we will cover ways we can verify the outcome of a rendering in more detail
235+
With the basics out of the way, next we will look at how to pass parameters and inject services into our component under test. After that, we will cover the ways in which we can verify the outcome of a rendering in more detail
236236

237237
- <xref:passing-parameters-to-components>
238238
- <xref:inject-services>

docs/site/docs/interaction/trigger-renders.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ To trigger a re-render of a component under test, a reference to it through a <x
99

1010
In `.razor` based tests, using the <xref:Bunit.TestContext>'s <xref:Bunit.TestContext.Render``1(Microsoft.AspNetCore.Components.RenderFragment)> method also returns an <xref:Bunit.IRenderedComponent`1> (as opposed to the <xref:Bunit.TestContext.Render(Microsoft.AspNetCore.Components.RenderFragment)> method which returns the more simple <xref:Bunit.IRenderedFragment>).
1111

12-
If you have a <xref:Bunit.IRenderedFragment> or a <xref:Bunit.IRenderedComponent`1> in a test, but need a child component's <xref:Bunit.IRenderedComponent`1>, then use the `FindComponent<TComponent>()` or the `FindComponents<TComponent>()` methods, which traverses down the render tree and finds rendered components.
12+
If you have a <xref:Bunit.IRenderedFragment> or a <xref:Bunit.IRenderedComponent`1> in a test, but need a child component's <xref:Bunit.IRenderedComponent`1>, then use the `FindComponent<TComponent>()` or the `FindComponents<TComponent>()` methods, which traverse down the render tree and finds rendered components.
1313

1414
With a <xref:Bunit.IRenderedComponent`1>, it is possible to cause the component to render again directly through the [`Render()`](xref:Bunit.RenderedComponentRenderExtensions.Render``1(Bunit.IRenderedComponentBase{``0})) method or one of the [`SetParametersAndRender()`](xref:Bunit.RenderedComponentRenderExtensions.SetParametersAndRender``1(Bunit.IRenderedComponentBase{``0},System.Action{Bunit.ComponentParameterCollectionBuilder{``0}})) methods, or indirectly through the [`InvokeAsync()`](xref:Bunit.IRenderedFragmentBase.Bunit.RenderedFragmentInvokeAsyncExtensions.InvokeAsync(System.Action)) method.
1515

docs/site/docs/misc-test-tips.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ This makes the tooling in Visual Studio and other IDEs automatically assign the
4141

4242
## Capturing logs from ILogger in test output
4343

44-
It can sometimes be helpful to capture log messages sent to `ILogger`'s in the components under test and/or the bUnit and Blazor internals.
44+
It can sometimes be helpful to capture log messages sent to `ILogger` types in the components under test and/or the bUnit and Blazor internals.
4545

4646
With xUnit, this can be done as follows:
4747

docs/site/docs/providing-input/inject-services-into-components.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ In bUnit, you register the services in the `Services` collection _before_ you re
1414
> [!NOTE]
1515
> The `AddSingleton()` method is only available on the `Services` collection if you **import the `Microsoft.Extensions.DependencyInjection` namespace in your test class**.
1616
17-
The following sections demonstrate how to do. The examples we will cover will test the `<WeatherForecasts>` component listed below, which depends on the `IWeatherForecastService` service, injected in line 1:
17+
The following sections demonstrate how to do this. The examples we will cover will test the `<WeatherForecasts>` component listed below, which depends on the `IWeatherForecastService` service, injected in line 1:
1818

1919
[!code-cshtml[WeatherForecasts.razor](../../../samples/components/WeatherForecasts.razor?highlight=1)]
2020

@@ -49,7 +49,7 @@ Here is a test where the fallback service provider is used:
4949

5050
[!code-csharp[](../../../samples/tests/xunit/FallBackServiceProviderUsage.cs?start=11&end=16)]
5151

52-
In this example, the `DummyService` is provided by the fallback service provider, since it is not register in the default service provider.
52+
In this example, the `DummyService` is provided by the fallback service provider, since it is not registered in the default service provider.
5353

5454
## Further reading
5555

docs/site/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ This test uses bUnit's test context to render the `Counter` component with the `
3838

3939
### NuGet downloads
4040

41-
bUnit is available on NuGet in various incarnations. Most should just pick the [bUnit](https://www.nuget.org/packages/bunit/) package:
41+
bUnit is available on NuGet in various incarnations. Most users should just pick the [bUnit](https://www.nuget.org/packages/bunit/) package:
4242

4343
| Name | Description | NuGet Download Link |
4444
| ----- | ----- | ---- |

0 commit comments

Comments
 (0)