0

我无法理解我的管道测试有什么不正确的地方。

它是用于从数组创建 MatTableDataSource 的管道。

这是我的管道:

import { Pipe, PipeTransform } from '@angular/core';
import { MatTableDataSource } from '@angular/material';

@Pipe({
  name: 'dataSource'
})
export class DataSourcePipe implements PipeTransform {

  transform(array: any[]): any {
    return array ? new MatTableDataSource(array) : new MatTableDataSource([]);
  }
}

该测试用于检查数组是否为空,它返回一个空的 matTableDataSource

import { TestBed, async, inject } from '@angular/core/testing';
import { DataSourcePipe } from './datasource-pipe.pipe';
import { MatTableDataSource } from '@angular/material';

 describe('Pipe: Datasource', () => {
   let pipe: DataSourcePipe;

   beforeEach(() => {
     pipe = new DataSourcePipe();
   });


   describe('Tests', () => {

    it('providing an empty array returns empty matTableDatasource', () => {
       expect(pipe.transform([])).toEqual(new MatTableDataSource([]));
    });
   });
 });

此测试失败:

PhantomJS 2.1.1 (Linux 0.0.0) Pipe: Datasource Tests providing an empty array returns empty matTableDatasource FAILED
Expected $._filter.observers[0]._parent._parent._parent._parent._parent._parent._parent._parent._parent.destination._next = Function to equal Function.
Expected $._filter.observers[0]._parent._parent._parent._parent._parent._parent._parent._parent.project = Function to equal Function.
Expected $._filter.observers[0]._parent._parent._parent._parent._parent._parent._parent.observables[0].destination.destination.array[0].operator.project = Function to equal Function.
Expected $._filter.observers[0]._parent._parent._parent._parent._parent._parent._parent.observables[0].operator.project = Function to equal Function.
Expected $._filter.observers[0]._parent._parent._parent._parent._parent.project = Function to equal Function.
Expected $._filter.observers[0]._parent._parent.project = Function to equal Function.
Expected $.sortingDataAccessor = Function to equal Function.
Expected $.sortData = Function to equal Function.
Expected $.filterPredicate = Function to equal Function.

而且我不明白为什么,我还控制台记录了“toEqual”的两个部分并且是相同的。

有人可以告诉我我做错了什么吗?

4

0 回答 0