Skip to content

Commit

Permalink
Update main with documentation in stable (#1541)
Browse files Browse the repository at this point in the history
* docs: Fix heading (#1537)

* Fix heading

Fix heading not rendering correctly.

* Fix heading

Be gone, crazy space.

* docs: Fix AddFakePersistentComponentState examples (Fixes #1539) (#1540)

---------

Co-authored-by: Martin Costello <[email protected]>
Co-authored-by: Steven Giesel <[email protected]>
  • Loading branch information
3 people authored Sep 4, 2024
1 parent 3d03d6f commit f022007
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions docs/site/docs/test-doubles/faking-persistentcomponentstate.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ bUnit comes with fake version of the `PersistentComponentState` type in Blazor t
To use the fake `PersistentComponentState` in bUnit, call the `AddFakePersistentComponentState` extension method on `TestContext`:

```csharp
var fakeState = AddFakePersistentComponentState();
var fakeState = this.AddFakePersistentComponentState();
```

Calling `AddFakePersistentComponentState` returns a `FakePersistentComponentState` type, which has three methods; one to persist data, one to get persisted data, and one that triggers any "OnPersisting" callbacks added to the `PersistentComponentState`.

To add data to the `PersistentComponentState` before running a test, i.e. to verify that a component uses the persisted state, use the `Persist` method:

```csharp
var fakeState = AddFakePersistentComponentState();
var fakeState = this.AddFakePersistentComponentState();
var key = "STATE KEY";
var data = ...; // data to persist
Expand All @@ -31,7 +31,7 @@ fakeState.Persist(key, data);
To trigger a callback registered with the `PersistentComponentState.RegisterOnPersisting` method, use the `TriggerOnPersisting` method on `FakePersistentComponentState`:

```csharp
var fakeState = AddFakePersistentComponentState();
var fakeState = this.AddFakePersistentComponentState();

// render component
Expand All @@ -41,7 +41,7 @@ fakeState.TriggerOnPersisting();
To check if data has been persisted, use the `TryTake` method:

```csharp
var fakeState = AddFakePersistentComponentState();
var fakeState = this.AddFakePersistentComponentState();
var key = "STATE KEY";

// render component, call TriggerOnPersisting
Expand Down Expand Up @@ -95,7 +95,7 @@ To test that the `<FetchData>` component uses persisted weather data instead of

```csharp
// Arrange
var fakeState = AddFakePersistentComponentState();
var fakeState = this.AddFakePersistentComponentState();

// Persist a single weather forecast with a temperature of 42
fakeState.Persist("weather-data", new [] { new WeatherForecast { Temperature = 42 } });
Expand All @@ -111,7 +111,7 @@ To test that the `<FetchData>` component correctly persists weather data when it

```csharp
// Arrange
var fakeState = AddFakePersistentComponentState();
var fakeState = this.AddFakePersistentComponentState();
var cut = RenderComponent<FetchData>();

// Act - trigger the FetchData components PersistForecasts method
Expand Down

0 comments on commit f022007

Please sign in to comment.