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

TestContext.Render(renderFragment) and MarkupMatches(renderFragment) #262

Merged
merged 3 commits into from
Nov 23, 2020

Conversation

egil
Copy link
Member

@egil egil commented Nov 22, 2020

This PR adds support for cleaner razor based tests by making it possible for TestContext type to render RenderFragment's. This allows us to pass RenderFragments created inline in .razor files directly to the TestContext.

Also added support for passing RenderFragments to MarkupMatches' expected argument. This looks like this in practice, e.g. in a CounterTest.razor file:

@inherits TestContext
@code
{
    [Fact]
    public void Test()
    {
        var cut = Render(@<Counter />);
        cut.Find("button").Click();
        cut.Find("p").MarkupMatches(@<p>Current count: 1</p>);
    }
}

PR meta checklist

  • Pull request is targeting at DEV branch.
  • Pull request is linked to all related issues, if any.
  • I have read the CONTRIBUTING.md document.

Content checklist

  • My code follows the code style of this project and AspNetCore coding guidelines.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • I have updated the appropriate sub section in the CHANGELOG.md.
  • I have added, updated or removed tests to according to my changes.
    • All tests passed.

@egil egil changed the title Added ability to render a fragment to test context, and pass it as th… TestContext.Render(renderFragment) and MarkupMatches(renderFragment) Nov 22, 2020
@codecov
Copy link

codecov bot commented Nov 22, 2020

Codecov Report

Merging #262 (6bd4872) into dev (a3fc598) will increase coverage by 1.85%.
The diff coverage is 84.26%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #262      +/-   ##
==========================================
+ Coverage   80.58%   82.44%   +1.85%     
==========================================
  Files         116      117       +1     
  Lines        3508     3566      +58     
  Branches      444      467      +23     
==========================================
+ Hits         2827     2940     +113     
+ Misses        546      479      -67     
- Partials      135      147      +12     
Impacted Files Coverage Δ
src/bunit.core/RazorTesting/FragmentContainer.cs 100.00% <ø> (ø)
src/bunit.core/TestContextBase.cs 100.00% <ø> (ø)
src/bunit.core/TestServiceProvider.cs 96.36% <ø> (+1.72%) ⬆️
...it.web/Extensions/Internal/AngleSharpExtensions.cs 66.66% <66.66%> (+16.66%) ⬆️
...nit.web/Asserting/MarkupMatchesAssertExtensions.cs 62.41% <79.24%> (+41.95%) ⬆️
src/bunit.web/TestContext.cs 93.75% <83.33%> (-6.25%) ⬇️
src/bunit.web/Extensions/TestContextExtensions.cs 100.00% <100.00%> (ø)
...it.web/Extensions/TestServiceProviderExtensions.cs 100.00% <100.00%> (ø)
src/bunit.web/RazorTesting/Fixture.cs 94.20% <100.00%> (-0.25%) ⬇️
src/bunit.web/RazorTesting/SnapshotTest.cs 78.57% <100.00%> (-1.43%) ⬇️
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a3fc598...6bd4872. Read the comment docs.

@egil egil merged commit 13eb090 into dev Nov 23, 2020
@egil egil deleted the spike/better-razor-tests branch November 23, 2020 22:01
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.

1 participant