Is there a way to add imports?
See original GitHub issueWhen you:
- use the NGRX Store module
- use it inside of a feature module
- use it in a component within that module
- and you want to test it, then they require you to add an additional import.
It looks like this:
imports: [
StoreModule.forRoot({}), // This is the extra import
StoreModule.forFeature('yourFeature', fromFeature.reducers)
]
Without the extra import, you can’t use the Store
service within your component. It complains about missing providers.
But you can’t just add StoreModule.forRoot({})
to your feature module since it would defeat the whole purpose of having StoreModule.forFeature('yourFeature', fromFeature.reducers)
. The extra import is only for the test.
Is there a way to add new imports?
I recall there used to be an .imports()
method on the shallow class instance, but it’s no longer there.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Python import: Advanced Techniques and Tips
This tutorial will provide a thorough overview of Python's import statement and how it works. The import system is powerful, and you'll learn...
Read more >5. The import system — Python 3.11.1 documentation
The import statement is the most common way of invoking the import machinery, but it is not the only way. Functions such as...
Read more >import - JavaScript - MDN Web Docs - Mozilla
In order to use the import declaration in a source file, the file must be interpreted by the runtime as a module. In...
Read more >How to import modules, packages, functions, etc. in Python
In Python, you can import the standard library, packages installed with pip, your own packages, and so on, with the import statement.5.
Read more >How To Import Modules in Python 3 - DigitalOcean
In Python, modules are accessed by using the import statement. When you do this, you execute the code of the module, keeping the...
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
For reference, if someone else finds this wanting to add an import, you could do it like so:
That makes sense to me.
I thought it would be necessary to have an
.include()
for the NgRx example, and I was wrong. I ended up doing it more in line with how the NgRx guys want you to write tests (for feature modules).I have another case that may also have some simpler/better workaround that I just haven’t figured out yet.
It basically comes down to only loading
BrowserAnimationModule
in the root module for my actual app (because of lazy loading https://github.com/angular/angular/issues/15829) but needing it for my tests too. In this case it’s adding an import rather than just replacing one. (Or at least that’s what it seems to be).