MCPcopy Create free account
hub / github.com/angular/components / testSortWithValues

Function testSortWithValues

src/material/table/table-data-source.spec.ts:21–34  ·  view source on GitHub ↗

Test the data source's `sortData` function.

(values: (string | number)[])

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 1

sortDataMethod · 0.45

Tested by

no test coverage detected