2017-04-19 00:55:46 +00:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import u from '../lib'
|
2015-08-05 11:29:30 +00:00
|
|
|
|
|
|
|
describe('u.reject', () => {
|
2015-08-23 17:48:32 +00:00
|
|
|
it('can reject by index', () => {
|
2017-04-19 00:55:46 +00:00
|
|
|
const result = u.reject((_, index) => index === 1, [3, 4, 5])
|
2015-08-23 17:48:32 +00:00
|
|
|
|
2017-04-19 00:55:46 +00:00
|
|
|
expect(result).to.eql([3, 5])
|
|
|
|
})
|
2015-08-23 17:48:32 +00:00
|
|
|
|
2016-01-14 17:04:47 +00:00
|
|
|
it('can reject with callback shorthand', () => {
|
2017-04-19 00:55:46 +00:00
|
|
|
const result = u.reject('bad', [{ bad: true }, { bad: false }])
|
2016-01-14 17:04:47 +00:00
|
|
|
|
2017-04-19 00:55:46 +00:00
|
|
|
expect(result).to.eql([{ bad: false }])
|
|
|
|
})
|
2016-01-14 17:04:47 +00:00
|
|
|
|
2017-04-19 00:55:46 +00:00
|
|
|
it("returns the same instance if reject doesn't make changes", () => {
|
|
|
|
const object = { foo: [1, 2, 3] }
|
|
|
|
const result = u(
|
|
|
|
{
|
2020-04-02 14:16:13 +00:00
|
|
|
foo: u.reject((x) => x === 'Justin Bieber'),
|
2017-04-19 00:55:46 +00:00
|
|
|
},
|
|
|
|
object
|
|
|
|
)
|
2016-06-07 03:51:11 +00:00
|
|
|
|
2017-04-19 00:55:46 +00:00
|
|
|
expect(result).to.equal(object)
|
|
|
|
})
|
2016-06-07 03:51:11 +00:00
|
|
|
|
|
|
|
it('returns a different instance if reject makes changes', () => {
|
2017-04-19 00:55:46 +00:00
|
|
|
const object = { foo: [1, 2, 3, 4] }
|
|
|
|
const result = u(
|
|
|
|
{
|
2020-04-02 14:16:13 +00:00
|
|
|
foo: u.reject((x) => x === 4),
|
2017-04-19 00:55:46 +00:00
|
|
|
},
|
|
|
|
object
|
|
|
|
)
|
2016-06-07 03:51:11 +00:00
|
|
|
|
2017-04-19 00:55:46 +00:00
|
|
|
expect(result).to.not.equal(object)
|
|
|
|
})
|
2016-06-07 03:51:11 +00:00
|
|
|
|
2015-08-05 11:29:30 +00:00
|
|
|
it('freezes the result', () => {
|
2017-04-19 00:55:46 +00:00
|
|
|
expect(Object.isFrozen(u.reject('a', []))).to.be.true
|
|
|
|
})
|
|
|
|
})
|