New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests on standalone component fails after update to 14.12.0 #7490
Comments
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();
});
}); |
Also, could you check if this change solves the issue? ng-mocks.zip |
And this should help to understand which module is causing the issue: ng-mocks.zip |
I don't seem to have the issue with your second zip. The spec passes now and this is the output:
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. |
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. |
The fix: #7492 |
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.
|
Hi there, unfortunately, without clear guidance how the issue appears, it's hard to track it. With I would suggest to change approach of calling 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()
); |
Thanks, Im am closing this ticket. |
Aha, that's good. I'll keep it open to cover |
Description of the bug
Tests fail after updating to 14.12.0
this is for a standalone component using angular 17 for a standalone component.
works with 14.11.0
An example: the following test runs fine in 14.11.0 but fails in 14.12.0
Expected vs actual behavior
Expected: the test passes.
Actual :
The text was updated successfully, but these errors were encountered: