Comments (10)
The fix: #7492
from ng-mocks.
Hi @LPCmedia, could you create a min example with the failure?
I cannot reproduce on my side:
import { TestBed } from '@angular/core/testing';
import { MockBuilder } from 'ng-mocks';
import { provideMockStore } from '@ngrx/store/testing';
import { RouterTestingModule } from '@angular/router/testing';
import {provideTranslocoScope, TranslocoModule} from '@ngneat/transloco';
import {Component, InjectionToken} from "@angular/core";
const APT_INSTALL_API_CONFIGURATION = new InjectionToken('APT_INSTALL_API_CONFIGURATION');
@Component({
selector: 'target',
standalone: true,
imports: [TranslocoModule],
providers: [provideTranslocoScope({
scope: 'core',
})],
template: `
<nav *transloco="let t">
<span>{{ t('core.test') }}</span>
</nav>
`,
})
class AppComponent {}
describe('AppComponent', () => {
beforeEach(() => {
return MockBuilder(AppComponent)
.keep(AppComponent)
.mock(TranslocoModule)
.provide({
provide: APT_INSTALL_API_CONFIGURATION,
useValue: {
host: 'foo.com',
basePrefix: '/',
port: 1,
},
})
});
beforeEach(() => TestBed.configureTestingModule({
imports: [AppComponent, RouterTestingModule],
providers: [provideMockStore({})]
}).compileComponents()
);
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
});
from ng-mocks.
Also, could you check if this change solves the issue? ng-mocks.zip
from ng-mocks.
And this should help to understand which module is causing the issue: ng-mocks.zip
from ng-mocks.
I don't seem to have the issue with your second zip. The spec passes now and this is the output:
● Console
console.log
isExportedOnRoot _CommonModule
at isExportedOnRoot (../../../node_modules/ng-mocks/index.js:5791:17)
console.log
init-ng-modules _CommonModule
at ../../../node_modules/ng-mocks/index.js:5853:25
console.log
isExportedOnRoot _CommonModule
at isExportedOnRoot (../../../node_modules/ng-mocks/index.js:5791:17)
Let me know if the repro is still needed for this bug ?
I may get to it tonight anyway as I am having unrelated issues with a NullInjectorError with an ngrx store following examples on the site with a renderFactory.
from ng-mocks.
aha.... interesting... it would be great to get an example with a failure on the current version.
I'll release the fix now, but the issue is I don't know how to cover it with tests.
from ng-mocks.
Fix works well thanks. And of course the repro is not reproducing....Its hard to reproduce everything in our private code base including the re-adding all the jest transforms and other fun configuration we need to add.
Let me know if you want to track under a separate issue. I will keep you posted should I find something, but I suspect that in the ngrx case we have some meta-reducer's at play that are may cause some strange behaviours.
NullInjectorError: No provider for _Store!
at NullInjector.get (../../../node_modules/@angular/core/fesm2022/core.mjs:5601:27)
at R3Injector.slice (../../../node_modules/@angular/core/fesm2022/core.mjs:6044:33)
at R3Injector.prop (../../../webpack:/ng-mocks/libs/ng-mocks/src/lib/common/ng-mocks-global-overrides.ts:378:33)
at R3Injector.get (../../../webpack:/ng-mocks/libs/ng-mocks/src/lib/mock-service/helper.create-clone.ts:17:59)
at R3Injector.slice (../../../node_modules/@angular/core/fesm2022/core.mjs:6044:33)
at R3Injector.prop (../../../webpack:/ng-mocks/libs/ng-mocks/src/lib/common/ng-mocks-global-overrides.ts:378:33)
at R3Injector.get (../../../webpack:/ng-mocks/libs/ng-mocks/src/lib/mock-service/helper.create-clone.ts:17:59)
at _TestBedImpl.inject (../../../node_modules/@angular/core/fesm2022/testing.mjs:1844:62)
at Function.inject (../../../node_modules/@angular/core/fesm2022/testing.mjs:1697:37)
at src/app/shared/components/helpline-numbers/helpline-numbers.component.spec.ts:44:27
at fakeAsyncFn (../../../node_modules/zone.js/bundles/zone-testing.umd.js:2083:34)
at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invoke (../../../node_modules/zone.js/bundles/zone.umd.js:411:30)
at ProxyZoneSpec.Object.<anonymous>.ProxyZoneSpec.onInvoke (../../../node_modules/zone.js/bundles/zone-testing.umd.js:300:43)
at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invoke (../../../node_modules/zone.js/bundles/zone.umd.js:410:56)
at Zone.Object.<anonymous>.Zone.run (../../../node_modules/zone.js/bundles/zone.umd.js:165:47)
at Object.wrappedFunc (../../../node_modules/zone.js/bundles/zone-testing.umd.js:789:34)```
from ng-mocks.
Hi there,
unfortunately, without clear guidance how the issue appears, it's hard to track it.
With isExportedOnRoot _CommonModule
, I can try to find a way to produce it.
However, for NullInjectorError: No provider for _Store!
looks like a normal failure when injector tries to get a service which wasn't defined in TestBed
.
I would suggest to change approach of calling MockBuilder
and TestBed.configureTestingModule
for the same test, because both of them have create independent contexts, and it can easily lead to missed injection.
The right way would be something like that:
beforeEach(() => {
return MockBuilder([AppComponent, RouterTestingModule], [TranslocoModule])
.provide(provideMockStore({}))
.provide({
provide: APT_INSTALL_API_CONFIGURATION,
useValue: {
host: 'foo.com',
basePrefix: '/',
port: 1,
},
})
});
instead of
beforeEach(() => {
return MockBuilder(AppComponent)
.keep(AppComponent)
.mock(TranslocoModule)
.provide({
provide: APT_INSTALL_API_CONFIGURATION,
useValue: {
host: 'foo.com',
basePrefix: '/',
port: 1,
},
})
});
beforeEach(() => TestBed.configureTestingModule({
imports: [AppComponent, RouterTestingModule],
providers: [provideMockStore({})]
}).compileComponents()
);
from ng-mocks.
Thanks, Im am closing this ticket.
FYI what was missing and made the rxjs test was the return statement on MockBuilder. 🤦
from ng-mocks.
Aha, that's good.
I'll keep it open to cover _CommonModule
somehow in the future.
from ng-mocks.
Related Issues (20)
- support vitest
- ngMocksUniverse.global
- Bug: MockMiddleware{Index} HOT 1
- update links in the repo HOT 2
- update sponsor links in the repo HOT 2
- Bug: cannot set return value of DI'ed pipe HOT 1
- Bug: `.keep(ReactiveFormsModule)` does not actually keep HOT 4
- Bug: Angular 17.1.0 `input.required()` issues HOT 15
- Feature Request: Documentation for functional route guards without the use of NgModule
- Bug: Injection of mocked service fails for nested service ... but only sometimes ...
- Bug: cannot `.replace()` a component that has an abstract base class HOT 3
- Bug: formatHtml on MockedComponentFixture / DebugElement won't give expected value
- Bug: try to avoid recursive parsing when a standalone component imports itself
- Bug: Incompatibility of MockComponent with new viewChild signal function HOT 8
- Bug: MockComponent (Standalone) mocks all components not just the ones specified HOT 3
- Bug: MockRender throws an error on mat-tab HOT 3
- MockComponent function set Signal Inputs as Decorator Inputs
- Bug: Erroneous test setup due to the usage of contentChildren HOT 3
- Feature Request: release angular18 version HOT 8
- Bug: fail CI on missing package-lock.json sync HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ng-mocks.