Skip to content

Value cannot be null, Parameter 'jsObjectReference' when using AspNetCore Title component #311

@dawidr

Description

@dawidr

I've a problem writing test for a page which is using Microsoft.AspNetCore.Components.Web.Extensions.Head.Title component.
No issues when I remove the Title. The page looks like this:

@page "/sample"

<Title Value="Sample"></Title>

<div>@Text</div>

@code {
    [Parameter]
    public string Text { get; set; } = string.Empty;
}

And here is the test:

using Bunit;
using Bunit.TestDoubles;
using Xunit;

namespace Tests
{
    public class SampleTests
    {
        private TestContext _context;

        public SampleTests()
        {
            _context = new TestContext();
            _context.Services.AddMockJSRuntime();
        }

        [Fact]
        public void PageShouldRender()
        {
            var html = _context.RenderComponent<Sample>(parameters =>
                parameters.Add(p => p.Text, "Sample"));
        }

    }
}

Error:
{"Value cannot be null. (Parameter 'jsObjectReference')"}

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions