{"id":18937397,"url":"https://github.com/verifytests/verify.bunit","last_synced_at":"2025-07-18T01:37:27.199Z","repository":{"id":249971502,"uuid":"833064432","full_name":"VerifyTests/Verify.Bunit","owner":"VerifyTests","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-23T17:19:19.000Z","size":419,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-29T01:53:45.838Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VerifyTests.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"license.txt","code_of_conduct":"code_of_conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"VerifyTests"}},"created_at":"2024-07-24T09:30:05.000Z","updated_at":"2024-12-23T17:19:22.000Z","dependencies_parsed_at":"2024-08-20T19:40:54.035Z","dependency_job_id":"95b37d20-4354-4f42-855a-37bee0f7a81f","html_url":"https://github.com/VerifyTests/Verify.Bunit","commit_stats":null,"previous_names":["verifytests/verify.bunit"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerifyTests%2FVerify.Bunit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerifyTests%2FVerify.Bunit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerifyTests%2FVerify.Bunit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VerifyTests%2FVerify.Bunit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VerifyTests","download_url":"https://codeload.github.com/VerifyTests/Verify.Bunit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232032040,"owners_count":18462966,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T12:11:01.918Z","updated_at":"2025-07-18T01:37:27.188Z","avatar_url":"https://github.com/VerifyTests.png","language":"C#","funding_links":["https://github.com/sponsors/VerifyTests"],"categories":[],"sub_categories":[],"readme":"\u003c!--\nGENERATED FILE - DO NOT EDIT\nThis file was generated by [MarkdownSnippets](https://github.com/SimonCropp/MarkdownSnippets).\nSource File: /readme.source.md\nTo change this file edit the source file and then run MarkdownSnippets.\n--\u003e\n\n# \u003cimg src=\"/src/icon.png\" height=\"30px\"\u003e Verify.Bunit\n\n[![Discussions](https://img.shields.io/badge/Verify-Discussions-yellow?svg=true\u0026label=)](https://github.com/orgs/VerifyTests/discussions)\n[![Build status](https://ci.appveyor.com/api/projects/status/spyere4ubpl1tca8?svg=true)](https://ci.appveyor.com/project/SimonCropp/Verify-Bunit)\n[![NuGet Status](https://img.shields.io/nuget/v/Verify.Bunit.svg?label=Verify.Bunit)](https://www.nuget.org/packages/Verify.Bunit/)\n\nSupport for rendering a [Blazor Component](https://docs.microsoft.com/en-us/aspnet/core/blazor/#components) to a verified file via [bunit](https://bunit.egilhansen.com). Verify.Bunit uses the bUnit APIs to take a snapshot (metadata and html) of the current state of a Blazor component. Since it leverages the bUnit API, snapshots can be on a component that has been manipulated using the full bUnit feature set, for example [trigger event handlers](https://bunit.egilhansen.com/docs/interaction/trigger-event-handlers.html).\n\n**See [Milestones](../../milestones?state=closed) for release notes.**\n\n\n## Sponsors\n\n### Entity Framework Extensions\u003c!-- include: zzz. path: /docs/zzz.include.md --\u003e\n\n[Entity Framework Extensions](https://entityframework-extensions.net/) is a major sponsor and is proud to contribute to the development this project.\n\n[![Entity Framework Extensions](docs/zzz.png)](https://entityframework-extensions.net)\u003c!-- endInclude --\u003e\n\n\n## Component\n\nThe below samples use the following Component:\n\n\u003c!-- snippet: BlazorApp/TestComponent.razor --\u003e\n\u003ca id='snippet-BlazorApp/TestComponent.razor'\u003e\u003c/a\u003e\n```razor\n\u003cdiv\u003e\n    \u003ch1\u003e@Title\u003c/h1\u003e\n    \u003cp\u003e@Person.Name\u003c/p\u003e\n    \u003cbutton\u003eMyButton\u003c/button\u003e\n\u003c/div\u003e\n\n@code {\n\n    [Parameter]\n    public string Title { get; set; } = \"My Test Component\";\n\n    [Parameter]\n    public Person Person { get; set; }\n\n    public bool Intitialized;\n\n    protected override Task OnInitializedAsync()\n    {\n        Intitialized = true;\n        return Task.CompletedTask;\n    }\n\n}\n```\n\u003csup\u003e\u003ca href='/src/BlazorApp/TestComponent.razor#L1-L23' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-BlazorApp/TestComponent.razor' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n## NuGet\n\n* https://nuget.org/packages/Verify.Bunit\n\n\n## Usage\n\nEnable at startup:\n\n\u003c!-- snippet: BunitEnable --\u003e\n\u003ca id='snippet-BunitEnable'\u003e\u003c/a\u003e\n```cs\n[ModuleInitializer]\npublic static void Initialize() =\u003e\n    VerifyBunit.Initialize();\n```\n\u003csup\u003e\u003ca href='/src/Tests/ModuleInitializer.cs#L5-L11' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-BunitEnable' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\nThis test:\n\n\u003c!-- snippet: BunitComponentTest --\u003e\n\u003ca id='snippet-BunitComponentTest'\u003e\u003c/a\u003e\n```cs\n[Fact]\npublic Task Component()\n{\n    using var context = new TestContext();\n    var component = context.RenderComponent\u003cTestComponent\u003e(\n        builder =\u003e\n        {\n            builder.Add(\n                _ =\u003e _.Title,\n                \"New Title\");\n            builder.Add(\n                _ =\u003e _.Person,\n                new()\n                {\n                    Name = \"Sam\"\n                });\n        });\n    return Verify(component);\n}\n\n[Fact]\npublic Task MarkupFormattable_NodeList()\n{\n    using var context = new TestContext();\n    var component = context.RenderComponent\u003cTestComponent\u003e(\n        builder =\u003e\n        {\n            builder.Add(\n                _ =\u003e _.Title,\n                \"New Title\");\n            builder.Add(\n                _ =\u003e _.Person,\n                new()\n                {\n                    Name = \"Sam\"\n                });\n        });\n    return Verify(component.Nodes);\n}\n\n[Fact]\npublic Task MarkupFormattable_single_Element()\n{\n    using var context = new TestContext();\n    var component = context.RenderComponent\u003cTestComponent\u003e(\n        builder =\u003e\n        {\n            builder.Add(\n                _ =\u003e _.Title,\n                \"New Title\");\n            builder.Add(\n                _ =\u003e _.Person,\n                new()\n                {\n                    Name = \"Sam\"\n                });\n        });\n    return Verify(component.Nodes.First()\n        .FirstChild);\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/Samples.cs#L3-L66' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-BunitComponentTest' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\nWill produce:\n\nThe component rendered as html `...Component.verified.html`:\n\n\u003c!-- snippet: Tests/Samples.Component.verified.html --\u003e\n\u003ca id='snippet-Tests/Samples.Component.verified.html'\u003e\u003c/a\u003e\n```html\n\u003cdiv\u003e\n  \u003ch1\u003eNew Title\u003c/h1\u003e\n  \u003cp\u003eSam\u003c/p\u003e\n  \u003cbutton\u003eMyButton\u003c/button\u003e\n\u003c/div\n```\n\u003csup\u003e\u003ca href='/src/Tests/Samples.Component.verified.html#L1-L5' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-Tests/Samples.Component.verified.html' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\nAnd the current model rendered as txt `...Component.verified.txt`:\n\n\u003c!-- snippet: Tests/Samples.Component.verified.txt --\u003e\n\u003ca id='snippet-Tests/Samples.Component.verified.txt'\u003e\u003c/a\u003e\n```txt\n{\n  Instance: {\n    Intitialized: true,\n    Title: New Title,\n    Person: {\n      Name: Sam\n    }\n  },\n  NodeCount: 9\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/Samples.Component.verified.txt#L1-L10' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-Tests/Samples.Component.verified.txt' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n## Exclude Component\n\nRendering of the Component state (Samples.Component.verified.txt from above) can be excluded by\nusing `excludeComponent`.\n\n\u003c!-- snippet: BunitEnableExcludeComponent --\u003e\n\u003ca id='snippet-BunitEnableExcludeComponent'\u003e\u003c/a\u003e\n```cs\n[ModuleInitializer]\npublic static void Initialize() =\u003e\n    VerifyBunit.Initialize(excludeComponent: true);\n```\n\u003csup\u003e\u003ca href='/src/ExcludeComponentTests/ModuleInitializer.cs#L3-L9' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-BunitEnableExcludeComponent' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n## Scrubbing\n\n\n## Integrity check\n\nIn Blazor an integrity check is applied to the `dotnet.*.js` file.\n\n```\n\u003cscript src=\"_framework/dotnet.5.0.2.js\" defer=\"\" integrity=\"sha256-AQfZ6sKmq4EzOxN3pymKJ1nlGQaneN66/2mcbArnIJ8=\" crossorigin=\"anonymous\"\u003e\u003c/script\u003e\n```\n\nThis line will change when the dotnet SDK is updated.\n\n\n## Noise in rendered template\n\nBlazor uses `\u003c!--!--\u003e` to delineate components in the resulting html. Some empty lines can be rendered when components are stitched together.\n\n\n## Resulting scrubbing\n\n\u003c!-- snippet: scrubbers --\u003e\n\u003ca id='snippet-scrubbers'\u003e\u003c/a\u003e\n```cs\n// remove some noise from the html snapshot\nVerifierSettings.ScrubEmptyLines();\nBlazorScrubber.ScrubCommentLines();\nVerifierSettings.ScrubLinesWithReplace(\n    line =\u003e\n    {\n        var scrubbed = line.Replace(\"\u003c!--!--\u003e\", \"\");\n        if (string.IsNullOrWhiteSpace(scrubbed))\n        {\n            return null;\n        }\n\n        return scrubbed;\n    });\nHtmlPrettyPrint.All();\nVerifierSettings.ScrubLinesContaining(\"\u003cscript src=\\\"_framework/dotnet.\");\n```\n\u003csup\u003e\u003ca href='/src/Tests/ModuleInitializer.cs#L16-L35' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-scrubbers' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\n## Icon\n\n[Helmet](https://thenounproject.com/term/helmet/9554/) designed\nby [Leonidas Ikonomou](https://thenounproject.com/alterego) from [The Noun Project](https://thenounproject.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fverifytests%2Fverify.bunit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fverifytests%2Fverify.bunit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fverifytests%2Fverify.bunit/lists"}