效果规范文件中的 SnackBar
SnackBar at effect spec file
我正在尝试测试我的效果规范文件。我在效果文件中使用 matSnackBar。
当我 运行 它时,_snackbar 被声明为未定义,然后是测试字段。
这就是我试图做的:
describe('InquiryWizardEffects', () => {
let actions: Observable<any>;
let effects: InquiryWizardEffects;
let inquiryService: MockInquiryService;
let _snackBar: MatSnackBar;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
NxModule.forRoot(),
StoreModule.forRoot({}),
EffectsModule.forRoot([]),
MatSnackBarModule,
],
providers: [
InquiryWizardEffects,
DataPersistence,
provideMockActions(() => actions),
{ provide: InquiriesService, useClass: MockInquiryService },
{ provide: MatSnackBar}
]
});
_snackBar= TestBed.get(MatSnackBar);
effects = TestBed.get(InquiryWizardEffects);
inquiryService = TestBed.get(InquiriesService);
});
我做错了什么?
编辑
这是我得到的错误:
'Cannot read property 'openFromComponent' of undefined '
它在我做的时候来了:
this._snackBar.openFromComponent(CreatedEntitySnackBarComponent, {
duration: environment.longDurationSnackBar,
panelClass: [style],
horizontalPosition: 'right',
data: {
title: title,
entityId: entityId
}
});
}
您可以使用 "useValue" 提供 SnackBar 并伪造它。
describe('InquiryWizardEffects', () => {
let actions: Observable<any>;
let effects: InquiryWizardEffects;
let inquiryService: MockInquiryService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
NxModule.forRoot(),
StoreModule.forRoot({}),
EffectsModule.forRoot([]),
MatSnackBarModule,
],
providers: [
InquiryWizardEffects,
DataPersistence,
provideMockActions(() => actions),
{ provide: InquiriesService, useClass: MockInquiryService },
{ provide: MatSnackBar, useVale: {openFromComponent: (param1, param2) => { return; }}},
]
});
effects = TestBed.get(InquiryWizardEffects);
inquiryService = TestBed.get(InquiriesService);
});
试试看是否可行。
我正在尝试测试我的效果规范文件。我在效果文件中使用 matSnackBar。 当我 运行 它时,_snackbar 被声明为未定义,然后是测试字段。 这就是我试图做的:
describe('InquiryWizardEffects', () => {
let actions: Observable<any>;
let effects: InquiryWizardEffects;
let inquiryService: MockInquiryService;
let _snackBar: MatSnackBar;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
NxModule.forRoot(),
StoreModule.forRoot({}),
EffectsModule.forRoot([]),
MatSnackBarModule,
],
providers: [
InquiryWizardEffects,
DataPersistence,
provideMockActions(() => actions),
{ provide: InquiriesService, useClass: MockInquiryService },
{ provide: MatSnackBar}
]
});
_snackBar= TestBed.get(MatSnackBar);
effects = TestBed.get(InquiryWizardEffects);
inquiryService = TestBed.get(InquiriesService);
});
我做错了什么?
编辑
这是我得到的错误:
'Cannot read property 'openFromComponent' of undefined '
它在我做的时候来了:
this._snackBar.openFromComponent(CreatedEntitySnackBarComponent, {
duration: environment.longDurationSnackBar,
panelClass: [style],
horizontalPosition: 'right',
data: {
title: title,
entityId: entityId
}
});
}
您可以使用 "useValue" 提供 SnackBar 并伪造它。
describe('InquiryWizardEffects', () => {
let actions: Observable<any>;
let effects: InquiryWizardEffects;
let inquiryService: MockInquiryService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
NxModule.forRoot(),
StoreModule.forRoot({}),
EffectsModule.forRoot([]),
MatSnackBarModule,
],
providers: [
InquiryWizardEffects,
DataPersistence,
provideMockActions(() => actions),
{ provide: InquiriesService, useClass: MockInquiryService },
{ provide: MatSnackBar, useVale: {openFromComponent: (param1, param2) => { return; }}},
]
});
effects = TestBed.get(InquiryWizardEffects);
inquiryService = TestBed.get(InquiriesService);
});
试试看是否可行。