Update TestBed configs with missing declarations, imports and providers #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #1
The errors detailed in #1 indicate that components, modules or services are missing from the TestBed configurations.
In short, the Angular TestBed makes zero assumptions, and needs you to wire in all child components as declarations, any dependent modules you need to import (like routers, layout modules, etc) and any Dependency Injected services as providers. Doing this for the components and services you write in your own app is fairly easy, but sometimes you inherit some messy configurations from third-party libraries.
In this case, the use of the Nebular UI means there's a load of extra stuff you need to provide in order for that to work in your testing environment. I found some examples of how the Nebular dev team tests their own stuff and borrowed some of their strategies. Once I had this working in the
app.component.spec.ts
file, I moved the majority into a separate module (nebular-testing.module.ts
so it is easily packaged and re-usable across any of your future spec files.Hopefully, this unblocks your testing efforts. If you have any other Angular or testing related questions, please don't hesitate to reach out here or on twitter.