提问者:小点点

未捕获(在Promise中):TypeError:无法读取未定义的属性“替换”


获取未捕获(在Promise中):TypeError:无法读取fix. detectChange()方法上未定义的属性“替换”。

我正在使用Jest和角版本8运行测试用例注意:我的其他测试用例工作正常,因此没有配置错误

测试规范

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);
    });

}));

组件化

@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);
    });
}

有人能建议更改和错误吗?

长原木


共1个答案

匿名用户

看起来这个错误发生在组件TradeInvoicesComponent的超文本标记语言中。可能在某个属性上使用了替换函数,并且该属性没有定义。尝试在trade-发票.组件. html中找到。替换