typescript(option): test: added tests for bind
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
dcd55c5047
commit
1fc2ef32e4
4 changed files with 498 additions and 2 deletions
typescript/option/src/helpers
32
typescript/option/src/helpers/bind.test.ts
Normal file
32
typescript/option/src/helpers/bind.test.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { expect } from 'chai'
|
||||
import { bind } from './bind'
|
||||
import { Some, None } from '../types'
|
||||
import { constantly } from '@thi.ng/compose'
|
||||
|
||||
describe('The bind helper', () => {
|
||||
it('should return none for any callback when given None', () => {
|
||||
// act
|
||||
const result = bind(Some, None)
|
||||
|
||||
// assert
|
||||
expect(result).to.equal(None)
|
||||
})
|
||||
|
||||
describe('When given Some', () => {
|
||||
it('should return None if the callback returns None', () => {
|
||||
// act
|
||||
const result = bind(constantly(None), Some(3))
|
||||
|
||||
// assert
|
||||
expect(result).to.equal(None)
|
||||
})
|
||||
|
||||
it('should return Some if the callback returns Some', () => {
|
||||
// act
|
||||
const result = bind(x => Some(x + 1), Some(3))
|
||||
|
||||
// assert
|
||||
expect(result).to.equal(Some(4))
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue