2023-09-19 12:10:17 -04:00
|
|
|
import { deepEqual as equal } from 'node:assert/strict'
|
|
|
|
import { metaltest } from 'metaltest'
|
|
|
|
const test = metaltest('Sort')
|
|
|
|
export { test }
|
|
|
|
|
|
|
|
import { sortby } from '../index.js'
|
|
|
|
|
|
|
|
const data = [
|
|
|
|
{ age: 40, name: "Persone 1", new: true },
|
|
|
|
{ age: 17, name: "Persone 2", new: false },
|
|
|
|
]
|
|
|
|
|
|
|
|
test('sort by name ascending', () => {
|
|
|
|
const result = data.sort(sortby(['name']))
|
|
|
|
|
|
|
|
|
|
|
|
equal(result, [
|
|
|
|
{ age: 40, name: "Persone 1", new: true },
|
|
|
|
{ age: 17, name: "Persone 2", new: false },
|
|
|
|
])
|
|
|
|
})
|
|
|
|
|
|
|
|
test('sort by age ascending', () => {
|
|
|
|
const result = data.sort(sortby(['age']))
|
|
|
|
|
|
|
|
|
|
|
|
equal(result, [
|
|
|
|
{ age: 17, name: "Persone 2", new: false },
|
|
|
|
{ age: 40, name: "Persone 1", new: true },
|
|
|
|
])
|
|
|
|
})
|
|
|
|
|
|
|
|
test('sort by age descending', () => {
|
|
|
|
const result = data.sort(sortby(['age', 'desc']))
|
|
|
|
|
|
|
|
|
|
|
|
equal(result, [
|
|
|
|
{ age: 40, name: "Persone 1", new: true },
|
|
|
|
{ age: 17, name: "Persone 2", new: false },
|
|
|
|
])
|
|
|
|
})
|
|
|
|
|
2023-09-19 14:20:25 -04:00
|
|
|
test('sort by new descending', () => {
|
|
|
|
const result = data.sort(sortby(['new', 'desc']))
|
|
|
|
|
|
|
|
|
|
|
|
equal(result, [
|
|
|
|
{ age: 40, name: "Persone 1", new: true },
|
|
|
|
{ age: 17, name: "Persone 2", new: false },
|
|
|
|
])
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2023-09-19 12:10:17 -04:00
|
|
|
import { runifmain, summaryreporter, errorreporter } from 'metaltest'
|
|
|
|
await runifmain(import.meta, () => test.run(summaryreporter(), errorreporter()))
|