Rask.Testing
0.20.1-alpha.0.228
See the version list below for details.
dotnet add package Rask.Testing --version 0.20.1-alpha.0.228
NuGet\Install-Package Rask.Testing -Version 0.20.1-alpha.0.228
<PackageReference Include="Rask.Testing" Version="0.20.1-alpha.0.228" />
<PackageVersion Include="Rask.Testing" Version="0.20.1-alpha.0.228" />
<PackageReference Include="Rask.Testing" />
paket add Rask.Testing --version 0.20.1-alpha.0.228
#r "nuget: Rask.Testing, 0.20.1-alpha.0.228"
#:package Rask.Testing@0.20.1-alpha.0.228
#addin nuget:?package=Rask.Testing&version=0.20.1-alpha.0.228&prerelease
#tool nuget:?package=Rask.Testing&version=0.20.1-alpha.0.228&prerelease
Rask.Testing
Unit-test Rask components — render a component to HTML, invoke its event handlers, and assert on the re-rendered markup. No browser, no server, no WebSocket.
using Rask.Testing;
public sealed class Counter : Component
{
private int _count;
protected override Component? Render() =>
Button(Type: "button", OnClick: () => _count++)[$"Count: {_count}"];
}
[Fact]
public async Task Clicking_increments()
{
var page = RaskTest.Render(new Counter());
Assert.Contains("Count: 0", page.Html);
await page.ClickAsync(); // dispatch the click handler + re-render
Assert.Contains("Count: 1", page.Html);
}
API
RaskTest.Render(component, services?)→ aRenderedComponent. Renders the component with its event handlers wired; pass anIServiceProviderwhen the component constructor-injects services.RaskTest.Render(factory, services?)— same, but the factory runs on every render, so the tree is rebuilt from your current state each time. Use it whenever a re-render should see changed props:RaskTest.Render(() => Form(model)[Input(() => model.Name)]). Thecomponentoverload renders one fixed instance, so a tree you build at the call site keeps the values it was built with.RaskTest.RenderDocument(app, services?)— renders the component the way a host does, with the whole document composed around it, so you can assert on the page: the doctype,<html lang>, the<head>every mounted component contributed to,<body class>.Renderadds no markup of its own, which is what keeps an assertion about a component from quietly becoming one about a page — reach for this only when the page is the thing under test.RenderedComponent.Html— the current markup, reflecting the latest state..WaitForAsync(text | predicate, timeout?)— re-renders until the markup contains the text (or the predicate accepts it), then returns it; throws with the last markup after 5 seconds by default. Use it for a component that loads inOnMountAsync:Rendermounts it, but the load completes on a continuation, so the result is not in the markup yet whenRenderreturns..ClickAsync(json?)/.InvokeAsync(handlerId, json?)— dispatch a handler (optionally with a JSON event payload like"{\"value\":\"hi\"}"for an input) and re-render; returns the newHtml..HandlerId(domEvent)— the handler id wired to"click"/"input"/"change"/"submit"/….Attr(name)— the firstname="…"attribute value in the currentHtml..HandlerIds(domEvent)/.Attrs(name)— every match, in document order. Index these to target one of several same-event elements:await page.InvokeAsync(page.HandlerIds("click")[1]).Markup.Attr(html, name)/Markup.Attrs(html, name)— the same lookups over any HTML string.
Finding elements
.Find(selector) returns the element, so an assertion can say which one rather than substring-matching
the whole page — which is brittle against exactly the attribute-order invariant the framework pins.
var badge = page.Find("#items li.selected .badge");
Assert.Equal("7", badge.TextContent);
Assert.Equal(["3", "7"], page.FindAll(".badge").Select(b => b.TextContent));
Assert.Equal("7 shipped", page.TextOf("#items li.selected")); // whitespace collapsed
page.TestId("refresh"); // [data-testid="refresh"]
.Find throws when there is no match and when there is more than one — a test that silently
took the first of several keeps passing after somebody adds a second. Use .FindAll when several are the
point, and .Exists(selector) for presence.
The selector is a documented subset, and anything outside it throws rather than quietly matching
nothing: tag, *, #id, .class, [attr], [attr="v"], [attr^="v"], [attr$="v"], [attr*="v"],
:has-text("…"), and the descendant and > combinators. For anything else, give the element an id or a
data-* attribute — the test reads better for it too.
Driving one element
await page.On("#save").ClickAsync();
await page.On("#name").InputAsync("Ada");
await page.On("form#signup").SubmitAsync();
.HandlerId(domEvent) returns the first match in the document and .HandlerIds is indexed by
position — so adding an unrelated button above the one under test silently re-points the assertion and the
test keeps passing. .On(selector) names the element instead. (It's a handle rather than a
ClickAsync(selector) overload because ClickAsync already takes a string, the JSON payload.)
Fakes for the things a component needs
TestDownloadSink— anIDownloadSinkthat records what a component staged.Navigator.Downloadrefuses to run without one and tells you to "register a fake"; this is that fake. Assert on.Staged(FileName,ContentType,Bytes,.Text).TestFileBackend— anIBrowserFileBackendserving files a test staged in memory, so anOnFileshandler can be tested at all. Stage with.Add("notes.txt", "hello"), register it, thenpage.On("#picker").FilesAsync(file). The handler gets real files:OpenReadStream()returns the bytes andmaxAllowedSizeis enforced as the real backends enforce it. Without a backend registered the handler is handed an empty list — it still fires, so a test can pass while proving nothing..FormPayload(field, …)covers a file inside a submitted form;.Releasedrecords the framework's release call.TestServiceProvider— a minimalIServiceProviderfor handing a component the one or two services it resolves:TestServiceProvider.With<IBrowserFileBackend>(files), or.Add(...).Add(...)for several. Exists becauseRaskTest.Rendertakes anIServiceProviderand this package depends on no DI container.TestRoute.At("/search?q=hello%20world")— aRouteStateat a URL, query string parsed and decoded, repeated keys kept.TestRoute.NavigatorFor(state, downloads)wires theNavigator. Register theNavigatorin the provider and event dispatch enters its handler scope, so a component that navigates or downloads on click can be unit-tested at all.CapturingDiagnostics.Install()— captures the framework diagnostics raised while it is installed, so you can assert that a swallowed fault happened (or that none did). Swallow-and-log is the framework's designed behaviour for navigate faults, JS dispatch faults and faulted async lifecycle hooks, and without this there is no supported way to see them. Safe under xUnit's default parallelism: several captures can be installed at once, every one of them sees every diagnostic, and disposing one never unhooks another — so they may be disposed in any order. Because concurrent captures share the events, a test asserting on a count should filter to what it provoked (OfCategory(...)) rather than assert over everything captured..TryInvokeAsync(handlerId, json?)— dispatch only if the id is still live; returnsfalserather than throwing, so you can assert a handler is gone..Instance— the component object you passed in, for asserting its state directly..Render()— re-render after mutating external state the component reads.TestJSRuntime— anIJSRuntimethat records calls and returns canned values, for components that injectIJSRuntime. Register it in the provider, then assert with.ArgsFor(id)/.Calls/.CallCount(id); configure with.SetResponse(id, value)/.SetException(id, ex). An unconfigured call returnsdefault; a call configured with the wrong type now throws and names both types, rather than also returningdefault—SetResponse("getCount", 1)againstInvokeAsync<long>used to hand back0, indistinguishable from "not configured".RaskTest.EditContextProbe(capture)— placed inside aForm's children, hands you the form'sEditContextso you can assert validation state (GetValidationMessages,IsModified,IsValidating) that never appears in the markup.
Install
Reference from your test project. Rask.Core comes transitively from the app under test (via its
Rask.Server / Rask.Wasm reference), so you don't reference it directly.
dotnet add <YourApp>.Tests package Rask.Testing
See the testing guide for forms, validation, and DI examples.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.JSInterop (>= 10.0.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.20.1-alpha.0.261 | 0 | 9/8/2026 |
| 0.20.1-alpha.0.254 | 3 | 9/8/2026 |
| 0.20.1-alpha.0.252 | 21 | 9/8/2026 |
| 0.20.1-alpha.0.251 | 24 | 9/8/2026 |
| 0.20.1-alpha.0.250 | 32 | 9/8/2026 |
| 0.20.1-alpha.0.248 | 35 | 9/8/2026 |
| 0.20.1-alpha.0.247 | 30 | 9/8/2026 |
| 0.20.1-alpha.0.246 | 41 | 9/7/2026 |
| 0.20.1-alpha.0.245 | 36 | 9/7/2026 |
| 0.20.1-alpha.0.243 | 41 | 9/7/2026 |
| 0.20.1-alpha.0.242 | 38 | 9/7/2026 |
| 0.20.1-alpha.0.241 | 43 | 9/7/2026 |
| 0.20.1-alpha.0.240 | 47 | 9/7/2026 |
| 0.20.1-alpha.0.238 | 46 | 9/7/2026 |
| 0.20.1-alpha.0.237 | 45 | 9/7/2026 |
| 0.20.1-alpha.0.236 | 47 | 9/7/2026 |
| 0.20.1-alpha.0.235 | 50 | 9/7/2026 |
| 0.20.1-alpha.0.234 | 40 | 9/7/2026 |
| 0.20.1-alpha.0.228 | 39 | 9/4/2026 |
| 0.20.0 | 110 | 8/6/2026 |