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/docs/getting-started/fixture-options.md
+26-7Lines changed: 26 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,10 @@ Let us start by looking at the parameters that takes a method as input first. Th
27
27
28
28
In the example above, the setup and test methods are declared in a `@code { }` block nested inside the <xref:Bunit.Fixture> component. This visually groups the methods nicely to the <xref:Bunit.Fixture> component, but it's not a requirement.
29
29
30
-
You can have the methods anywhere inside the test component you want, which can be useful, if you for example have a common setup method that multiple Razor tests in the same test component shares. The methods can also be declared in the parameter directly, e.g.: `<Fixture Setup="f => f.Services.AddMockJsRuntime" ...>`.
30
+
You can have the methods anywhere inside the test component you want, which can be useful, if you for example have a common setup method that multiple Razor tests in the same test component shares. The methods can also be declared in the parameter directly, e.g.: `<Fixture Setup="f => f.Services.AddMockJsRuntime()" ...>`.
31
+
32
+
> [!TIP]
33
+
> Learn more about mocking and `AddMockJsRuntime()` on the <xref:mocking-ijsruntime> page.
31
34
32
35
**Other parameters**
33
36
@@ -80,10 +83,26 @@ The generic versions of <xref:Bunit.Fixture.GetComponentUnderTest``1> and <xref:
80
83
81
84
## Example
82
85
83
-
TODO:
86
+
Let's look at a complete example, where we have a simple task list component, `<SimpleTodo>`, listed below, that have a service injected, receive a cascading value, and changes between renders:
1. The fixture has both a setup and test method specified. The setup methods is used to register an empty list of tasks, that the `<SimpleTodo>` component requires.
103
+
2. The `<SimpleTodo>` component is wrapped in a `<CascadingValue>` component that passes down the "Theme" cascading value.
104
+
3. The first `<Fragment>` does not have an `Id`, since the `GetFragment()` method will pick the first fragment, if no `id` is provided to it.
105
+
4. The second `<Fragment Id="expected tasks">` does have an `Id` to make it possible to get it, through a call to the `GetFragment("expected tasks")` method.
106
+
5. The test uses the generic version of `GetComponentUnderTest<SimpleTodo>()`, which gives us access to the instance of `SimpleTodo`, and allows us to inspect its properties, e.g. `ThemeClass`.
84
107
85
-
1. Create a basic component that takes a cascading value, a service, and maybe some child content, and it should have a initial rendered output and something after e.g. a click event.
86
-
2. Add a setup method that registers the service
87
-
3. Add two fragments, one to verify the inital rendered output and one for the output after click.
88
-
4. Show how GetCompnentUnderTest returns not the cascading value
89
-
5. Show how get fragment is used with and without id, and returns fragments without
108
+
We will cover the details of the "act" and "assertion" step in the <xref:interaction> and <xref:verification> pages. Learn more about injecting services into components under test on the <xref:inject-services-into-components> page.
Copy file name to clipboardExpand all lines: docs/docs/getting-started/writing-razor-tests.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ title: Writing Tests in Razor Syntax for Blazor Components
10
10
11
11
A test for a Blazor component can be written in a Blazor component, using a mix of Razor and C# syntax. The advantage of this is the familiarity in declaring the component under test, and other HTML or Razor fragments that will be used in the test, _in Razor and HTML markup_. This is especially useful when testing components that takes a lot of parameters and child content as input.
12
12
13
-
> [!INFO]
13
+
> [!NOTE]
14
14
> Tests declared inside Blazor test components can be discovered and invoked individually, and will show up in e.g. Visual Studio's Test Explorer.
15
15
>
16
16
> However, they will _not_ show up before the Blazor test component has been compiled into C# by the Blazor compiler, and if there are compile-errors from the Blazor compiler, they might appear to come and go in the Test Explorer.
0 commit comments