Mocking of "Sub"-Components #254
-
Is it somehow possible when I write unit tests for component A which in its markup contains a component B to completely mock component B? To give an example of my question I'll refer to my current blazor learning project which is a Blazor Server app where we try to build Minesweeper. In this example Component A is the A Simplified
The
While writing unit tests for the Markup tests
While writing this entry here I discovered the diffing possibilities with e.g. Injected services Are there already any solutions implemented for my situations that I just can't find? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Mocking of components is on the TODO list. It is unfortunately not something that is available right now, see #53 and #17. You already discovered As for services, while we wait for mocking of components, the easiest approach is to have a common setup methods for all your tests in a test class (when using xunit you can use the constructor) and just register a mock of the service your inner component needs. Hope this helps! |
Beta Was this translation helpful? Give feedback.
Hi @dev-in-disguise
Mocking of components is on the TODO list. It is unfortunately not something that is available right now, see #53 and #17.
You already discovered
diff:ignore
which is the best option right now.As for services, while we wait for mocking of components, the easiest approach is to have a common setup methods for all your tests in a test class (when using xunit you can use the constructor) and just register a mock of the service your inner component needs.
Hope this helps!