Replies: 1 comment 6 replies
-
Hey, that is an interesting problem. Our Stubs do just mimic the public API, rather than implementing the class itself. That said you could use Add with a custom implementation: https://bunit.dev/api/Bunit.ComponentFactoryCollectionExtensions.html#Bunit_ComponentFactoryCollectionExtensions_Add__2_Bunit_ComponentFactoryCollection_ and basically mimicking the public api yourself and really inheriting from your Map type. |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We have a complex component, which uses a lot of JavaScript under the hood (an open layers map abstraction) and a layer of components, which use this base open layers component, applying business logic to it.
Due to the complexity, working just with bindings didn't work out, so we're exposing the element reference in the code behind and the component offers some methods. For example:
and in the code behind, exposing it:
This couples the components heavily, but we couldn't come up with a better solution here.
Anyway, generally, it is working out fine, but it doesn't seem to be possible to mock the Map reference with Bunit? What we tried so far:
Direct stub
This doesn't work, as the stub can't be cast, resulting in:
Interfacing of the reference
As Blazor can fill the reference with an interface, I've interfaces the component out:
This is generally a bit better, as it decouples at least the code behind, but it seems like BUnit then can't bind it:
Is there therefore any possibility to have unit tests, when using child-components with the @ref keyword? Or are there other approaches we could use to have some possibilities for automated tests?
Beta Was this translation helpful? Give feedback.
All reactions