Skip to main content
Module

x/rambda/source/lastIndexOf.spec.js

Faster and smaller alternative to Ramda
Go to Latest
File
import {lastIndexOf} from './lastIndexOf'import {lastIndexOf as lastIndexOfRamda} from 'ramda'import {compareCombinations} from './_internals/testUtils'import {possibleTargets, possibleIterables} from './indexOf.spec.js'
test('with NaN', () => { expect(lastIndexOf(NaN, [NaN])).toEqual(0)})
test('will throw with bad input', () => { expect(lastIndexOfRamda([], true)).toEqual(-1) expect(() => indexOf([], true)).toThrow()})
test('without list of objects - no R.equals', () => { expect(lastIndexOf(3, [1, 2, 3, 4])).toEqual(2) expect(lastIndexOf(10)([1, 2, 3, 4])).toEqual(-1)})
test('list of objects uses R.equals', () => { const listOfObjects = [{a: 1}, {b: 2}, {c: 3}] expect(lastIndexOf({c: 4}, listOfObjects)).toBe(-1) expect(lastIndexOf({c: 3}, listOfObjects)).toBe(2)})
test('list of arrays uses R.equals', () => { const listOfLists = [[1], [2, 3], [2, 3, 4], [2, 3], [1], []] expect(lastIndexOf([], listOfLists)).toBe(5) expect(lastIndexOf([1], listOfLists)).toBe(4) expect(lastIndexOf([2, 3, 4], listOfLists)).toBe(2) expect(lastIndexOf([2, 3, 5], listOfLists)).toBe(-1)})
test('with string as iterable', () => { expect(() => lastIndexOf('a', 'abc')).toThrowWithMessage( Error, `Cannot read property 'indexOf' of abc` ) expect(lastIndexOfRamda('a', 'abc')).toBe(0)})
describe('brute force', () => { compareCombinations({ fn: lastIndexOf, fnRamda: lastIndexOfRamda, firstInput: possibleTargets, secondInput: possibleIterables, callback: errorsCounters => { expect(errorsCounters).toMatchInlineSnapshot(` Object { "ERRORS_MESSAGE_MISMATCH": 0, "ERRORS_TYPE_MISMATCH": 34, "RESULTS_MISMATCH": 0, "SHOULD_NOT_THROW": 51, "SHOULD_THROW": 0, "TOTAL_TESTS": 170, } `) }, })})