-
-
Notifications
You must be signed in to change notification settings - Fork 86
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
ng-mocks is not in JIT mode and cannot resolve declarations #354
Comments
Hi @DzmVasileusky, usually this happens when an app building process imports something from If you get this error during build If you get this error during a test run |
@satanTime Actually I got this error because the component I tried to mock was imported from a wrong directory. |
That's interesting, was it a missing file, or a missing export in a file? I would appreciate if you could post the test file with the import and how it is mocked. Plus the path and the source of the file with the declaration. Then I can add a better error description for such a case. Thanks in advance! |
the component is here |
|
@DzmVasileusky, thanks! I'll do that. Happy coding! |
@satanTime Thank you! |
v11.10.1 has been released and contains a fix for the issue. Feel free to reopen the issue or to submit a new one if you meet any problems. |
If you are here because of the error in your tests:
I hope it helps. Thanks in advance! |
I had this error because I've accidentally added a pipe as a MockComponents argument |
I have this error after upgrading to Angular 13. I have the latest version of ng-mocks installed (I even deleted node_modules) and re-installed. "ng-mocks": "^12.5.0", import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatButtonModule } from '@angular/material/button';
import { MatDialogModule, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { CommonPipesModule } from '@common/pipes/common-pipes.module';
import { ConfirmationDialogComponent } from '../confirmation-dialog/confirmation-dialog.component';
import { AlertDialogComponent } from './alert-dialog.component';
fdescribe('AlertDialogComponent', () => {
let component: AlertDialogComponent;
let fixture: ComponentFixture<AlertDialogComponent>;
let resultHandler;
const setupTestBed = async (dialogDataValue: {
title?: string;
contentHtml?: string;
resultHandler: jasmine.Spy;
}) => {
await TestBed.configureTestingModule({
imports: [NoopAnimationsModule, MatDialogModule, MatButtonModule, CommonPipesModule],
declarations: [AlertDialogComponent],
providers: [
{
provide: MatDialogRef,
useValue: {
close: (dialogResult: any) => {}
}
},
{
provide: MAT_DIALOG_DATA,
useValue: dialogDataValue
}
]
}).compileComponents();
};
describe(' - Defaults', () => {
beforeEach(async () => {
resultHandler = jasmine.createSpy();
await setupTestBed({ resultHandler });
});
beforeEach(() => {
fixture = TestBed.createComponent(AlertDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
// expectations...
});
});
});
|
I am also having the issue @jkyoutsey mentioned in the exact same use-case you can find example project here with the result either in GitHub actions or just by downloading it and running |
Just updatet my Project to Angular 13 and iam facing the same Issue as @jkyoutsey. |
Same issue here. We do use @ngneat/spectator though but I did a rewrite on one Test to only use TestBed and got the same result. Since @vorant94 already shared a repo that reproduces the error, I'll not try to extract ours (though I could if that would help you further in any way). |
same issue here also. |
I have experienced the same issue. For testing I created a new angular 13 project, installed ng-mocks, changed the generated app-component test to use ng-mocks (MockBuilder and MockRender) and it has the same issue. |
same issue |
@satanTime can you reopen this please? any updates? Same error here with Angular 13. |
Hi all, this is the issue to follow: #1427 |
confirmed |
I just upgraded to ng-mocks 13 today. Thanks for getting it out soon. Unfortunately, still getting the same error with angular 13 and node 16. |
Hi @winnemucca, thank you for reporting that. Might you post an example of failing test? |
@satanTime unfortunately, I am not allowed to post code/tests from our code base. Here is the error message |
Understood. Might you paste here angular version, material version and jest / jasmine version? If you are using best - might you confirm that imports aren't mocked by jest, and without MockModule, the failing test works well? |
"jest": "27.2.3 I had the declaration mocked. The file was not using |
Ah, I see. If the declaration has been mocked my jest imports, then it doesn't contain angular decorators anymore and cannot be mocked by The right way here is either to import the original module and to use |
Hi @winnemucca, were you able to check whether removal of |
I got this error after upgrading my project from angular @12.2.16 to @13.2.4. However I was getting the exact same error:
My project versions:
After trying a lot of possible solutions a could solve my problem just reinstalling ng-mocks with the latest version and everything got fixed up and all tests were passing successfully. Update ng-mocks to the latest version with:
Good lucky, hope this help someone else. |
@satanTime I apologize. I should have gotten back to you sooner. Switched projects, but our issue boiled down to the |
Hi @Skauyedauty, thanks for the update! Please let me know, If you have more feedback and would like to discuss improvements of |
I'm going to close this issue again. @winnemucca, could you try with the latest Thank you in advance. |
I updated our app to angular 13 and get this error on our tests with ng-mocks 12.5. Tried updating to ng-mocks 13.2 but then browser/tests hangs (using cpu) after compile and before first test. Removing usage of ng-mocks all working. With Angular 12 and ng-mocks 12.2 all was working fine. |
Hi @rbirkgit, Thanks for the info. I'll comment in a different issue. This one is correct. For angular 13, you need ng-mocks 13. |
ng-mocks is not in JIT mode and cannot resolve declarations
I'm getting this error after did some refactoring on moving some code to external libraries.
What does this error mean and how to fix it?
The text was updated successfully, but these errors were encountered: