Я хочу проверить эту функцию
export const compare = selector => (a, b) => selector(a).localeCompare(selector(b))
В настоящее время функция сравнения вызывается как
const mapStateToProps = state => ({
items: getPolicies(state)
.map(d => d)
.sort(compare(d => d.name)),
})
Моя шутка выглядит так:
import each from 'jest-each'
import { compare } from './sorting'
describe('sorting functions test', () => {
describe('compare tests', () => {
const func = jest.fn(value => value.name)
each([{ name: 'hello' }, { name: 'world' }], func)
it('return -1', () => {
expect(compare(func)).toBe(-1)
})
})
})
Я просто не вижу / не могу найти способ передать / смоделировать d => d.name для аргумента.