Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update main with documentation in stable #1541

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,8 @@ When rendering a `RenderFragment` using the <xref:Bunit.TestContext.Render(Micro
}
```

## Passing query parameters (`SupplyParameterFromQuery`) to a component
## Passing query parameters (`SupplyParameterFromQuery`) to a component

In .NET 6 and later, components can receive parameters from a query string if the parameter is annotated with the `[SupplyParameterFromQuery]` attribute in addition to the `[Parameter]` attribute.

In .NET 8 however, the `[Parameter]` attribute is no longer required, which means a value cannot be passed to the component during testing using the normal methods, e.g. the <xref:Bunit.ComponentParameterCollectionBuilder`1>'s `Add` method, if a component parameter is only annotated with the `[SupplyParameterFromQuery]` attribute. Instead, pass a query string parameters by setting it using the <xref:Bunit.TestDoubles.FakeNavigationManager>.
Expand Down
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
Loading