Is it possible to test the Component in isolation without the HTML template?
See original GitHub issueIt seems that TestBed.configureTestingModule({ provider: MyComponent }).createComponents()
is being called for each shallow render. Is it possible to call it without TestBed.configureTestingModule({ provider: MyComponent }).createComponents()
? So it will look like this: TestBed.configureTestingModule({ provider: MyComponent })
I quite like the mocking ability with this library so it would be great if I could not call .createComponents()
in my tests. This is so I can test the component in isolation.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
How can I design/test an Angular component without running ...
Run the backend app (because of authentication checks etc. · Run the angular app ( ng serve handles this and will obviously auto...
Read more >Three Ways to Test Angular Components | by Victor Savkin
In this article we will look at three ways to test Angular components: isolated tests, shallow tests, and integration tests.
Read more >What is Component Testing? Techniques, Example Test Cases
Component testing done without isolation of other components in the software or application under test is referred as Component Testing Large.
Read more >Basics of testing components - Angular
Component class testing should be kept very clean and simple. It should test only a single unit. At first glance, you should be...
Read more >How to test React Components in isolation with Storybook
A guide and tutorial on how to test React components in isolation using Storybook. This includes guide uses a 'React counter' for code ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks so much @getsaf!
See the
Renderer2
is included as a dependency.constructor MyComponent(private Renderer2)
So when running the tests. The TestBed complains that it is not being provided. How do I work around this withshallow.render()
?Thanks for the tip! I am still just playing around with the lib to get an idea of how it works.
Side note: I would love to invite you to this Angular community I recently joined: https://www.angularnation.net/. It would be great if you could do a talk on this amazing lib you wrote. I find it REALLY helpful and I am sure other devs would too!
The console in your screenshot says that the
Renderer2
class is abstract, those can’t be used as Angular providers. I thinkRenderer2
is an internal Angular thing that you should not need to provide it manually. I’m also pretty sure you don’t need to useprovideMock
in your shallow options.IMO, rendering the component in a
beforeEach
is likely gonna cost you more code/headache than just callingshallow.render()
it in each test because you lose access all the built-into shallow-render tools like mocking/query/fixture, etc when you render before your test executes.Just suggestions here, but this kind of refactor could save you time and is more in-line with shallow-render’s intended use: