No provider for MatSnackBar error when trying to run "ng test"
You should import the module instead of the component.
import { MatSnackBar, MatSnackBarModule } from '@angular/material';....describe('BranchNameCellComponent', () => { let component: BranchNameCellComponent; let fixture: ComponentFixture<BranchNameCellComponent>; beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ BranchNameCellComponent ], imports: [ HttpClientTestingModule, ReactiveFormsModule, MatSnackBarModule ], schemas: [ NO_ERRORS_SCHEMA ] }).compileComponents(); })); it('should create', () => { fixture = TestBed.createComponent(BranchNameCellComponent); component = fixture.componentInstance; expect(component).toBeTruthy(); });});
For the issue related to the timeout, try adding this to your karma config file:
captureTimeout: 210000,browserDisconnectTolerance: 3, browserDisconnectTimeout : 210000,browserNoActivityTimeout : 210000,
I was facing this error when in my angular app, I was navigating to some module which was lazy loaded. This module was importing MatSnackBarModule
but I needed to import MatSnackBarModule
in app.module.ts
file as well
This has happened to me recently and I decided like this::
Include file aap.module.ts
import { MatSnackBarModule } from '@angular/material/snack-bar';......imports: [ ... MatSnackBarModule ]...
On file component or service:
import { MatSnackBar } from '@angular/material/snack-bar';......constructor(private snackBar: MatSnackBar) { }...