被捕获(承诺):TypeError:无法读取夹具.detectChanges()方法上未定义的属性“替换”。
我正在使用Jest和angular版本8运行测试用例 注意:我的其他测试用例工作正常,因此没有配置错误
Test.spec.ts
let requestListModel= new InvoicesRequestsListModel();
const initialState: InvoicesState = {
requestModel: new InvoicesRequestModel(),
requestListModel: new InvoicesRequestsListModel()
};
const tab: InvoiceResponse[] = [{
totalRecords: 1,
recordsReturned: 1,
invoices: [{
supplier: "Test Supplier",
invoiceId:"3fa85f64-5717-4562-b3fc-2c963f66af11",
}];
requestListModel.updateTableData(tab)
let invoiceStoreStub: Partial<InvoicesStore> = {
store: {
requestModel: new InvoicesRequestModel(),
requestListModel: requestListModel,
},
store$: new BehaviorSubject<InvoicesState>(initialState).asObservable(),
setInvoiceState: jest.fn(),
setRequestListModel: jest.fn(),
setRequestModel: jest.fn(),
};
describe('TradeInvoicesComponent', () => {
let fixture: ComponentFixture<TradeInvoicesComponent>;
let component: TradeInvoicesComponent;
let stubInvoiceService: InvoicesStore;
let selectMenu: SelectMenuTestHelper;
beforeEach(async(() => {
const configure: ConfigureFn = testBed => {
testBed.configureTestingModule({
declarations: [TradeInvoicesComponent],
imports: [HttpClientTestingModule, SharedModule, MatTableModule, BrowserAnimationsModule],
schemas: [NO_ERRORS_SCHEMA],
providers: [MatSnackBar, { provide: InvoicesStore, useValue: invoiceStoreStub }]
});
};
configureTests(configure).then(testBed => {
fixture = testBed.createComponent(TradeInvoicesComponent);
component = fixture.componentInstance;
stubInvoiceService = testBed.get(InvoicesStore);
fixture.detectChanges();
component.dataModel.updateTableData(tab);
});
}));
componat.ts
@Component({
selector: 'app-trade-invoices',
templateUrl: './trade-invoices.component.html',
styleUrls: ['./trade-invoices.component.scss']
})
export class TradeInvoicesComponent implements OnInit, AfterViewInit {
@ViewChild(MatPaginator, {static: false}) paginator: MatPaginator;
@ViewChild(MatSort, {static: false}) sort: MatSort;
@ViewChild('input', {static: false}) input: ElementRef;
@ViewChild(MatTable, {static: true}) table: MatTable<[]>;
@Output() paginate: EventEmitter<InvoicesRequestsListModel> = new EventEmitter();
@Output() request: EventEmitter<any> = new EventEmitter();
@Input() setSpinner: boolean;
public dataModel: InvoicesRequestsListModel = new InvoicesRequestsListModel();
displayedColumns: string[] = ['status', 'invoiceId', 'supplier', 'modifieddate'];
public uiPageNumber = 0;
private invoice: Invoice;
constructor(public store: InvoicesStore,
private paymentConsumerService: PaymentConsumerService, private
_snackBar: MatSnackBar) {
}
ngOnInit() {
this.dataModel.updateDataModel('pageNumber', this.apiPageNumber);
this.paginate.emit(this.dataModel);
}
ngAfterViewInit() {
this.store.store$.subscribe((invoice: InvoicesState) => {
this.table.renderRows();
});
this.sort.sortChange.subscribe(() => {
const sortOrder = `${this.sort.active} ${this.sort.direction}`;
this.changeSort(sortOrder);
});
}
任何人都可以提出更改和错误的建议。
长日志
错误:未捕获(承诺):TypeError:无法读取未定义的属性“ replace” TypeError:无法读取未定义的属性“替换” 在Object.eval [作为updateRenderer](ng:///DynamicTestModule/TradeInvoicesComponent.ngfactory.js:104:47) 在Object.debugUpdateRenderer [作为updateRenderer](/packages/core/src/view/services.ts:410:19) 在checkAndUpdateView(/packages/core/src/view/view.ts:368:12) 在callViewAction(/packages/core/src/view/view.ts:615:11) 在execEmbeddedViewsAction(/packages/core/src/view/view.ts:580:9) 在checkAndUpdateView(/packages/core/src/view/view.ts:360:3) 在callViewAction(/packages/core/src/view/view.ts:615:11) 在execComponentViewsAction(/packages/core/src/view/view.ts:559:7) 在checkAndUpdateView(/packages/core/src/view/view.ts:370:3) 在callViewAction(/packages/core/src/view/view.ts:615:11) 在execEmbeddedViewsAction(/packages/core/src/view/view.ts:580:9) 在checkAndUpdateView(/packages/core/src/view/view.ts:360:3) 在callViewAction(/packages/core/src/view/view.ts:615:11) 在execComponentViewsAction(/packages/core/src/view/view.ts:559:7) 在checkAndUpdateView(/packages/core/src/view/view.ts:370:3) 在callViewAction(/packages/core/src/view/view.ts:615:11) 在execComponentViewsAction(/packages/core/src/view/view.ts:559:7) 在checkAndUpdateView(/packages/core/src/view/view.ts:370:3) 在callWithDebugContext(/packages/core/src/view/services.ts:630:23) 在Object.debugCheckAndUpdateView [作为checkAndUpdateView](/packages/core/src/view/services.ts:347:10) 在ViewRef_.detectChanges(/packages/core/src/view/refs.ts:261:16) 在ComponentFixture._tick(//packages/core/testing/src/component_fixture.ts:107:28) 在package / core / testing / src / component_fixture.ts:120:36 在ZoneDelegate.Object..ZoneDelegate.invoke(/PROJECT/node_modules/zone.js/dist/zone.js:391:26) 在AsyncTestZoneSpec.Object..AsyncTestZoneSpec.onInvoke(/PROJECT/node_modules/zone.js/dist/async-test.js:106:39) 在ProxyZoneSpec.Object..ProxyZoneSpec.onInvoke(/PROJECT/node_modules/zone.js/dist/proxy.js:126:39) 在ZoneDelegate.Object..ZoneDelegate.invoke(/PROJECT/node_modules/zone.js/dist/zone.js:390:52) 在Object.onInvoke(/packages/core/src/zone/ng_zone.ts:273:25) 在ZoneDelegate.Object..ZoneDelegate.invoke(/PROJECT/node_modules/zone.js/dist/zone.js:390:52) 在Zone.Object..Zone.run(/PROJECT/node_modules/zone.js/dist/zone.js:150:43) 在NgZone.run(/packages/core/src/zone/ng_zone.ts:171:50) 在ComponentFixture.detectChanges(/packages/core/testing/src/component_fixture.ts:120:19) 在/PROJECT/s/chocolate-demo/src/app/trade/trade-invoices/test.spec.ts:82:12 在ZoneDelegate.Object..ZoneDelegate.invoke(/PROJECT/node_modules/zone.js/dist/zone.js:391:26) 在AsyncTestZoneSpec.Object..AsyncTestZoneSpec.onInvoke(/PROJECT/node_modules/zone.js/dist/async-test.js:106:39) 在ProxyZoneSpec.Object..ProxyZoneSpec.onInvoke(/PROJECT/node_modules/zone.js/dist/proxy.js:126:39) 在ZoneDelegate.Object..ZoneDelegate.invoke(/PROJECT/node_modules/zone.js/dist/zone.js:390:52) 在Zone.Object..Zone.run(/PROJECT/node_modules/zone.js/dist/zone.js:150:43) 在/PROJECT/node_modules/zone.js/dist/zone.js:910:34 在ZoneDelegate.Object..ZoneDelegate.invokeTask(/PROJECT/node_modules/zone.js/dist/zone.js:423:31) 在AsyncTestZoneSpec.Object..AsyncTestZoneSpec.onInvokeTask(/PROJECT/node_modules/zone.js/dist/async-test.js:90:25) 在ProxyZoneSpec.Object..ProxyZoneSpec.onInvokeTask(/PROJECT/node_modules/zone.js/dist/proxy.js:157:39) 在ZoneDelegate.Object..ZoneDelegate.invokeTask(/PROJECT/node_modules/zone.js/dist/zone.js:422:60) 在Zone.Object..Zone.runTask(/PROJECT/node_modules/zone.js/dist/zone.js:195:47) 在排水微任务队列(/PROJECT/node_modules/zone.js/dist/zone.js:601:35) 在processTicksAndRejections(内部/流程/task_queues.js:97:5) 在resolvePromise(/PROJECT/node_modules/zone.js/dist/zone.js:852:31) 在/PROJECT/node_modules/zone.js/dist/zone.js:917:17 在ZoneDelegate.Object..ZoneDelegate.invokeTask(/PROJECT/node_modules/zone.js/dist/zone.js:423:31) 在AsyncTestZoneSpec.Object..AsyncTestZoneSpec.onInvokeTask(/PROJECT/node_modules/zone.js/dist/async-test.js:90:25) 在ProxyZoneSpec.Object..ProxyZoneSpec.onInvokeTask(/PROJECT/node_modules/zone.js/dist/proxy.js:157:39) 在ZoneDelegate.Object..ZoneDelegate.invokeTask(/PROJECT/node_modules/zone.js/dist/zone.js:422:60) 在Zone.Object..Zone.runTask(/PROJECT/node_modules/zone.js/dist/zone.js:195:47) 在排水微任务队列(/PROJECT/node_modules/zone.js/dist/zone.js:601:35) 在processTicksAndRejections(internal / process / task_queues.js:97:5)
答案 0 :(得分:0)
好像此错误发生在组件TradeInvoicesComponent
的HTML中。可能在某些属性上使用了replace
函数,但未定义此属性。尝试在.replace
trade-invoices.component.html