Test the data source's `sortData` function.
(values: (string | number)[])
| 19 | |
| 20 | /** Test the data source's `sortData` function. */ |
| 21 | function testSortWithValues(values: (string | number)[]) { |
| 22 | // The data source and MatSort expect the list to contain objects with values, where |
| 23 | // the sort should be performed over a particular key. |
| 24 | // Map the values into an array of objects where each value is keyed by "prop" |
| 25 | // e.g. [0, 1, 2] -> [{prop: 0}, {prop: 1}, {prop: 2}] |
| 26 | const data = values.map(v => ({'prop': v})); |
| 27 | |
| 28 | // Set the active sort to be on the "prop" key |
| 29 | sort.active = 'prop'; |
| 30 | |
| 31 | const reversedData = data.slice().reverse(); |
| 32 | const sortedData = dataSource.sortData(reversedData, sort); |
| 33 | expect(sortedData).toEqual(data); |
| 34 | } |
| 35 | |
| 36 | it('should be able to correctly sort an array of numbers', () => { |
| 37 | testSortWithValues([-2, -1, 0, 1, 2]); |
no test coverage detected