moy-fp
Version:
A functional programming library.
59 lines (50 loc) • 1.14 kB
JavaScript
import Identity from '../../../src/Functor/Identity/index'
/**
* you should not use this similar funciton to get value anywhere in your application
* if you must need the inner value, you may need Comonad
* here is just simple for test
*/
const inspect = x => `Identity(${x.value})`
test('test Identity', () => {
expect(
inspect(Identity(12))
).toBe('Identity(12)')
})
test('test of', () => {
expect(
inspect(Identity.of(12))
).toBe('Identity(12)')
})
test('test map', () => {
expect(
inspect(Identity.of(12).map(x => x + 1))
).toBe('Identity(13)')
})
test('test join', () => {
expect(
inspect(Identity.of(
Identity.of(12)
).join())
).toBe('Identity(12)')
})
test('test chain', () => {
expect(
inspect(Identity.of(12).chain(
x => Identity.of(x + 1)
))
).toBe('Identity(13)')
})
test('test ap', () => {
expect(
inspect(Identity.of(x => x + 1).ap(
Identity.of(12)
))
).toBe('Identity(13)')
})
test('test Object.prototype.toString.call',() => {
expect(
Object.prototype.toString.call(
Identity.of(12)
)
).toBe('[object Identity]')
})