Skip to content

Commit b487084

Browse files
committed
updates to docs and samples
1 parent 21e484f commit b487084

22 files changed

+406
-22
lines changed

docs/csharp-examples.md

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
In the following examples, the terminology **component under test** (abbreviated CUT) is used to mean the component that is the target of the test. The examples below use the `Shouldly` assertion library as well. If you prefer not to use that just replace the assertions with the ones from your own favorite assertion library.
44

5-
All examples can be found in the [CodeOnlyTests](../sample/tests/CodeOnlyTests) folder in the [Sample project](../sample/).
5+
All examples can be found in the [Tests](../sample/tests/Tests) folder in the [Sample project](../sample/).
66

77
1. [Creating new test classes](#creating-new-test-classes)
88
2. [Testing components without parameters](#testing-components-without-parameters)
@@ -14,6 +14,7 @@ All examples can be found in the [CodeOnlyTests](../sample/tests/CodeOnlyTests)
1414
7. [Testing components that use on IJsRuntime](#testing-components-that-use-on-ijsruntime)
1515
7.1 [Verifying element references passed to InvokeAsync](#verifying-element-references-passed-to-invokeasync)
1616
8. [Testing components with injected dependencies](#testing-components-with-injected-dependencies)
17+
9. [Dispatching @on-events from tests](#Dispatching-on-events-from-tests)
1718

1819
## Creating new test classes
1920

@@ -55,7 +56,7 @@ The following unit-tests verifies that the [Counter.razor](../sample/src/Pages/C
5556
}
5657
```
5758

58-
The [CounterTest.cs](../sample/tests/CodeOnlyTests/Pages/CounterTest.cs) looks like this:
59+
The [CounterTest.cs](../sample/tests/Tests/Pages/CounterTest.cs) looks like this:
5960

6061
```csharp
6162
public class CounterTest : ComponentTestFixture
@@ -157,7 +158,7 @@ The component under test will be the [Aside.razor](../sample/src/Components/Asid
157158
}
158159
```
159160

160-
The [AsideTest.cs](../sample/tests/CodeOnlyTests/Components/AsideTest.cs) looks like this:
161+
The [AsideTest.cs](../sample/tests/Tests/Components/AsideTest.cs) looks like this:
161162

162163
```csharp
163164
public class AsideTest : ComponentTestFixture
@@ -329,7 +330,7 @@ To show how to pass an `EventCallback` to a component under test, we will use th
329330
}
330331
```
331332

332-
The relevant part of [ThemedButtonTest.cs](../sample/tests/CodeOnlyTests/Components/ThemedButtonTest.cs) looks like this:
333+
The relevant part of [ThemedButtonTest.cs](../sample/tests/Tests/Components/ThemedButtonTest.cs) looks like this:
333334

334335
```csharp
335336
public class ThemedButtonTest : ComponentTestFixture
@@ -456,7 +457,7 @@ To help us test the Mock JSRuntime, we have the [WikiSearch.razor](../sample/src
456457
}
457458
```
458459

459-
The [WikiSearchTest.cs](../sample/tests/CodeOnlyTests/Components/WikiSearchTest.cs) looks like this:
460+
The [WikiSearchTest.cs](../sample/tests/Tests/Components/WikiSearchTest.cs) looks like this:
460461

461462
```csharp
462463
public class WikiSearchTest : ComponentTestFixture
@@ -546,7 +547,7 @@ For example, consider the [FocussingInput.razor](../sample/src/Components/Focuss
546547
}
547548
```
548549

549-
The the [FocussingInputTest.cs](../sample/tests/CodeOnlyTests/Components/FocussingInputTest.cs) looks like this:
550+
The the [FocussingInputTest.cs](../sample/tests/Tests/Components/FocussingInputTest.cs) looks like this:
550551

551552
```csharp
552553
public class FocussingInputTest : ComponentTestFixture
@@ -594,7 +595,7 @@ internal class MockForecastService : IWeatherForecastService
594595
}
595596
```
596597

597-
With the mock in place, we can write the [FetchDataTest.cs](../sample/tests/CodeOnlyTests/Pages/FetchDataTest.cs), which looks like this:
598+
With the mock in place, we can write the [FetchDataTest.cs](../sample/tests/Tests/Pages/FetchDataTest.cs), which looks like this:
598599

599600
```csharp
600601
public class FetchDataTest : ComponentTestFixture
@@ -647,3 +648,61 @@ public class FetchDataTest : ComponentTestFixture
647648
- `Test002` creates a new instance of the mock service and registers that with the the service provider. It then renders the CUT and uses `WaitForNextRender` to pass the test data to the mock services task, which then completes and the CUT gets the data.
648649

649650
- In the assert step we expect the CUT to use a `ForecastDataTable` to render the forecast data. Thus, to make our assertion more simple and stable to changes, we render an instance of the `ForecastDataTable` use that to verify that the expected addition after the CUT receives the forecast data is as it should be.
651+
652+
## Dispatching `@on-events` during testing
653+
654+
In the previous sections we have seen a few examples of method calls that trigger `@on-event` handlers, e.g. `cut.Find(selector).Click()` that triggers the `@onclick` event handler attached to the element that matches the search query.
655+
656+
The following triggers are currently available in PascalCase, without the `@on`-prefix. E.g. the `@onbeforeactivate` event is available as `BeforeActivate()` in various overloads. I expect to add the missing events soon.
657+
658+
The currently available event triggers are:
659+
660+
```
661+
// General events
662+
@onactivate
663+
@onbeforeactivate
664+
@onbeforedeactivate
665+
@ondeactivate
666+
@onended
667+
@onfullscreenchange
668+
@onfullscreenerror
669+
@onloadeddata
670+
@onloadedmetadata
671+
@onpointerlockchange
672+
@onpointerlockerror
673+
@onreadystatechange
674+
@onscroll
675+
676+
// Focus events
677+
@onfocus
678+
@onblur
679+
@onfocusin
680+
@onfocusout
681+
682+
// Input events
683+
@onchange
684+
@oninput
685+
@oninvalid
686+
@onreset
687+
@onselect
688+
@onselectstart
689+
@onselectionchange
690+
@onsubmit
691+
692+
// Keyboard events
693+
@onkeydown
694+
@onkeyup
695+
@onkeypress
696+
697+
// Mouse events
698+
@onmouseover
699+
@onmouseout
700+
@onmousemove
701+
@onmousedown
702+
@onmouseup
703+
@onclick
704+
@ondblclick
705+
@onwheel
706+
@onmousewheel
707+
@oncontextmenu
708+
```

0 commit comments

Comments
 (0)