-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
Testing components with Telerik Grid throws System.InvalidOperationException #38
Comments
Hi @jpiell I will take a look later tonight if time allows, otherwise tomorrow. |
Thank you!
…On Tue, Jan 21, 2020 at 12:28 PM Egil Hansen ***@***.***> wrote:
Hi @jpiell <https://github.com/jpiell>
I will take a look later tonight if time allows, otherwise tomorrow.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#38>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHE7FBYVTITLEGGE25MYNFDQ64WEPANCNFSM4KJUVQUA>
.
|
@jpiell Hi, I work for Telerik. Sorry you're having trouble getting this set up. Because Blazor is new (still in preview), we haven't checked it against all integration points yet, this great testing framework by @egil is the perfect example. We are evaluating how we can provide better support for this, and I'm testing myself as well. Short term solution Long term solution |
Hi Ed,
I believe you are correct. It looks like Egil just implemented
IServiceCollection which should resolve the issue I am having. If
engineering could make IGridState public, I could mock the interface and
that would work as well (maybe even better).
I believe Beta 5 of the Razor.Component.Testing.Library will be released in
the next couple of days.
Thanks for keeping an eye on the issue.
Regards,
Jeff
…On Wed, Jan 22, 2020 at 10:49 AM Egil Hansen ***@***.***> wrote:
Closed #38
<#38>.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#38>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHE7FBYZ3VGG5YOSWZJGMWDQ7BTI5ANCNFSM4KJUVQUA>
.
|
Thank you sir!
…Sent from my iPhone
On Jan 22, 2020, at 10:49 AM, Egil Hansen ***@***.***> wrote:
@jpiell #39 should be fixed in the upcoming beta 5 release. My plan is to push that out in a day or two, so hopefully that will solve your issue.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Egil, You need to expose the IServiceCollection or we will not be able to register services. Thanks, Jeff |
jpiell, in beta-5, I just did a using System;
using Xunit;
using Egil.RazorComponents.Testing;
using Egil.RazorComponents.Testing.Diffing;
using Egil.RazorComponents.Testing.Asserting;
using Egil.RazorComponents.Testing.Mocking.JSInterop;
using Egil.RazorComponents.Testing.EventDispatchExtensions;
using Microsoft.Extensions.DependencyInjection;
namespace tspsc
{
public class Component1Test : ComponentTestFixture
{
[Fact]
public void Component1RendersCorrectly()
{
Services.AddMySrvs();
var cut = RenderComponent<Component1>();
cut.MarkupMatches(@"<div class=""my-component"">
This Blazor component is defined in the <strong>razorclasslib1</strong> package.
</div>");
}
}
public static class SrvColExt
{
public static void AddMySrvs(this IServiceCollection services)
{
services.AddSingleton(new object());
}
}
} And in razor based tests: @inherits TestComponentBase
<Fixture Setup="() => Services.AddMySrvs()">
<ComponentUnderTest><Component1/></ComponentUnderTest>
</Fixture> Both files compile and run on my computer. |
It looks as if Teleriks Am I missing something here? |
OK, so I installed into my testing project: Afterwords, both cs and razor tests compile and execute: using Xunit;
using Egil.RazorComponents.Testing;
using Egil.RazorComponents.Testing.Asserting;
using Microsoft.Extensions.DependencyInjection;
namespace tspsc
{
public class Component1Test : ComponentTestFixture
{
[Fact]
public void Component1RendersCorrectly()
{
Services.AddMySrvs();
Services.AddTelerikBlazor();
var cut = RenderComponent<Component1>();
cut.MarkupMatches(@"<div class=""my-component"">
This Blazor component is defined in the <strong>razorclasslib1</strong> package.
</div>");
}
}
public static class SrvColExt
{
public static void AddMySrvs(this IServiceCollection services)
{
services.AddSingleton(new object());
}
}
} @inherits TestComponentBase
<Fixture Setup="() => Services.AddTelerikBlazor()">
<ComponentUnderTest><Component1/></ComponentUnderTest>
</Fixture> |
Do I need to do something other than update my NuGet package? |
Not entirely sure. But if you follow the guide here: https://github.com/egil/razor-components-testing-library/wiki/Creating-a-new-test-project Install the template, and the use the That said, going to beta-5 should be enough, but you might also have to change/add some imports. |
All is good now - Thanks again for your help! |
@jpiell I was able to verify that a cut could render a Telerik Grid. @inherits TestComponentBase
@using Microsoft.AspNetCore.Components.Web
@using Egil.RazorComponents.Testing
@using Egil.RazorComponents.Testing.Diffing
@using Egil.RazorComponents.Testing.Asserting
@using Egil.RazorComponents.Testing.EventDispatchExtensions
@using Xunit
@using Telerik.Blazor.Components
@using Microsoft.Extensions.DependencyInjection;
<Fixture Test="Test1">
<ComponentUnderTest>
<TelerikRootComponent>
<TelerikGrid Data="forecasts">
<GridColumns>
<GridColumn Field="@nameof(WeatherForecast.Date)"></GridColumn>
</GridColumns>
</TelerikGrid>
</TelerikRootComponent>
</ComponentUnderTest>
</Fixture>
@code {
WeatherForecast[] forecasts = new List<WeatherForecast>().ToArray();
public void AddTelerikBlazor()
{
Services.AddMockJsRuntime();
Services.AddTelerikBlazor();
}
void Test1()
{
AddTelerikBlazor();
var cut = GetComponentUnderTest();
Assert.NotNull(cut);
}
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public string Summary { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
} |
Hi Ed, Would you happen to have any advice on how to get around: @inherits LayoutComponentBase
My tests are c# only. Thanks, Jeff Piell |
I believe this is the right start. However, I don't know how the various templates are described. @egil ?? <TelerikRootComponent> (cascading value)
<TelerikGrid Data="forecasts"> (component<T> parameter Data)
<GridColumns> (parameter of TelerikGrid)
<GridColumn Field="@nameof(WeatherForecast.Date)"></GridColumn> (GridColumn component cascading value from TelerikGrid, parameter Field)
</GridColumns>
</TelerikGrid>
</TelerikRootComponent> using Egil.RazorComponents.Testing;
using Xunit;
using Telerik.Blazor.Components;
using Microsoft.Extensions.DependencyInjection;
using System;
public class CounterTest : ComponentTestFixture
{
[Fact]
public void InitialHtmlIsCorrect()
{
Services.AddMockJsRuntime();
Services.AddTelerikBlazor();
// Arrange - renders the Counter component
var root = new TelerikRootComponent();
var cut = RenderComponent<TelerikGrid<WeatherForecast>>(
CascadingValue(root));
Assert.NotNull(cut);
}
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public string Summary { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
} |
Ed,
I got it to work!
Thanks for your help!
Jeff Piell
…On Thu, Jan 23, 2020 at 5:26 PM Ed Charbeneau ***@***.***> wrote:
@jpiell <https://github.com/jpiell>
I believe this is the right start. However, I don't know how the various
templates are described. @egil <https://github.com/egil> ??
Reference markup
<TelerikRootComponent> (cascading value)
<TelerikGrid Data="forecasts"> (component<T> parameter Data)
<GridColumns> (parameter of TelerikGrid)
<GridColumn ***@***.***(WeatherForecast.Date)"></GridColumn> (GridColumn component cascading value from TelerikGrid, parameter Field)
</GridColumns>
</TelerikGrid>
</TelerikRootComponent>
using Egil.RazorComponents.Testing;
using Xunit;
using Telerik.Blazor.Components;
using Microsoft.Extensions.DependencyInjection;
using System;
public class CounterTest : ComponentTestFixture
{
[Fact]
public void InitialHtmlIsCorrect()
{
Services.AddMockJsRuntime();
Services.AddTelerikBlazor();
// Arrange - renders the Counter component
var root = new TelerikRootComponent();
var cut = RenderComponent<TelerikGrid<WeatherForecast>>(
CascadingValue(root));
Assert.NotNull(cut);
}
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public string Summary { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#38>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHE7FBZU2XTT5QE6KUZ36BLQ7IKRNANCNFSM4KJUVQUA>
.
|
Ed, The example doesn't populate the grid. See the cut.Markup below:
|
It should actually be:
|
I am testing a component that uses the Telerik UI Blazor grid component. The grid component throws an exception: Message=Cannot provide a value for property 'State' on type 'Telerik.Blazor.Components.TelerikGrid, There is no registered service of type 'Telerik.Blazor.Components.Grid.State.IGridState'.
IGridState is private so it cannot be mocked.
I would like some help on how to work around this issue.
Attached is a sample app I put together to demonstrate the issue I am having.
SampleApp.zip
The text was updated successfully, but these errors were encountered: