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

[Unit Tests] Add Unit Tests in .razor files #844

Merged
merged 2 commits into from
Oct 11, 2023

Conversation

dvoituron
Copy link
Collaborator

Add Unit Tests in .razor files

Add Unit Tests in .razor files. See this bUnit documentation page

@using Xunit;
@inherits TestContext
@code
{
    [Fact]
    public void FluentButton_Title()
    {
        // Arrange && Act
        var cut = Render(@<FluentButton Title="My Title">My button</FluentButton>);

        // Assert
        cut.Verify();
    }

    [Fact]
    public void FluentButton_OnClick()
    {
        bool clicked = false;

        // Arrange
        var cut = Render(@<FluentButton OnClick="@(e => { clicked = true; } )">
                             My button
                          </FluentButton>);

        // Act
        cut.Find("fluent-button").Click();

        // Assert
        Assert.True(clicked);
    }
}

The Verify() method generates a .received.razor.html file (with the razor suffix) to distinguish "classic" received files in C#.

@github-actions
Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://black-pebble-0dc79cb03-844.westeurope.3.azurestaticapps.net

@vnbaaij vnbaaij merged commit a394049 into dev Oct 11, 2023
4 checks passed
@vnbaaij vnbaaij deleted the users/dvoituron/unittest-razor branch October 11, 2023 18:55
vnbaaij added a commit that referenced this pull request Oct 23, 2023
* fix: chinese abbreviated day name in FluentCalendar (#834)
* Minor documentation corrections (#837)
* Fix #836
* fix NavMenuLink width
* Rename solution file
* FluentMenu: move overlay into anchored section code
* Update version on index page
* Update Menu example
* Add some (😉) more tests
* [Unit Tests] Add Unit Tests in .razor files (#844)
* Fix gitignore
* Add FluentBadgeTests.razor
* Fix #845 Exception with NavMenuLink
* Fix #841 (#842)
* Hide collapse button on demo site menu and remove some commented code
* Fix #851
* Fix #852
* Update Fluent UI System Icons to 1.1.220 (#854)
* Small ToC script optimization
* Use latest SDKs
* Make demos better when opening in light/dark mode
* Fix initial theme switch setting
* Fix: Add '@' to keyframe for fade-out animation (#855)
* MessageBar: fix fadein effect
* [Accessibility] Fix some FluentButton and FluentNav aria attributes (#853)
* Fix FluentButton aria-label based on Title
* Fix NavMenu aria
* Fix Button Titles
* Fix unit Tests
* Add examples and documentation for the Persona component. (#843)
* Fix the Persona samples to use "@DataSource.SamplePicture" instead of using external resources.
* [Autocomplete] Update some Accessibility issues (#866)
* Update Autocomplete Accessibility items
* Fix Enter key when popup is closed
* Update Previous and Next titles (and Unit Tests)
* [FluentGrid] Add FluentGridItem with no breakpoints (#862)
* Add FluentGridItem with no breakpoints
* Update FluentValidationSummary.razor
* Fix #865
* docs: Update sample InputFileDefault.razor (#867)
* Update InputFileDefault.razor
* Update InputFileByCode.razor
* Update the documentation: inverse Api and Example sections
* fix: Implement DesignToken.WithDefault and use in Demo site (#869)
* Add 'System' option to theme settings
* Fix aria-orientation (#877)
* Fix #861 and also fix rendering in case of manual grid (#874)
* Fix security scanning workflow
* Add @ref to some layout components and adjust css of those to use css vars for font properties
* Update WhatsNew
* Update docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants