我正在进行单元测试,但是我遇到了错误
对象可能是'undefined'
it('should set the dataSource filter to the provided argument', () => {
component.applyFilter('filterValue');
expect(this.dataSource.filter).toEqual('filterValue');
})
it('should set the dataSource filter to the provided argument', () => {
component.applyFilter('filterValue');
expect(this.DMDataSource.filter).toEqual('filterValue');
})
expect(this)里面出现错误。
请让我知道。
答案 0 :(得分:1)
您应该在component.dataSource
块内使用this.dataSource
而不是expect
您需要评估在dataSource
实例中定义的component
it('should set the dataSource filter to the provided argument', () => {
component.applyFilter('filterValue');
expect(component.dataSource.filter).toEqual('filterValue');
})
it('should set the dataSource filter to the provided argument', () => {
component.applyFilter('filterValue');
expect(component.DMDataSource.filter).toEqual('filterValue');
})