typescript(option): test: wrote tests for filter
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
7e2e25263c
commit
f8e501b876
47
typescript/option/src/helpers/filter.test.ts
Normal file
47
typescript/option/src/helpers/filter.test.ts
Normal file
|
@ -0,0 +1,47 @@
|
|||
import { expect } from 'chai'
|
||||
import { constantly } from '@thi.ng/compose'
|
||||
import { filter } from './filter'
|
||||
import { None, Some } from '../types'
|
||||
import { someX } from '../../test/constants'
|
||||
|
||||
describe('The filter helper', () => {
|
||||
describe('When the predicate returns true', () => {
|
||||
const predicate = constantly(true)
|
||||
|
||||
it('should return None when given None', () => {
|
||||
// act
|
||||
const result = filter(predicate, None)
|
||||
|
||||
// assert
|
||||
expect(result).to.equal(None)
|
||||
})
|
||||
|
||||
it('should return Some(x) when given Some(x)', () => {
|
||||
// act
|
||||
const result = filter(predicate, someX)
|
||||
|
||||
// assert
|
||||
expect(result).to.equal(someX)
|
||||
})
|
||||
})
|
||||
|
||||
describe('When the predicate returns false', () => {
|
||||
const predicate = constantly(false)
|
||||
|
||||
it('should return None when given Some', () => {
|
||||
// act
|
||||
const result = filter(predicate, someX)
|
||||
|
||||
// assert
|
||||
expect(result).to.equal(None)
|
||||
})
|
||||
|
||||
it('should return None when given None', () => {
|
||||
// act
|
||||
const result = filter(predicate, None)
|
||||
|
||||
// assert
|
||||
expect(result).to.equal(None)
|
||||
})
|
||||
})
|
||||
})
|
|
@ -1,2 +1,7 @@
|
|||
import { Some } from '../src'
|
||||
|
||||
// general value to pass around
|
||||
export const x = Symbol('x')
|
||||
|
||||
// same as x but for some
|
||||
export const someX = Some(x)
|
||||
|
|
|
@ -8,5 +8,6 @@
|
|||
"downlevelIteration": true,
|
||||
"target": "es6"
|
||||
},
|
||||
"include": ["src", "sandbox", "test"]
|
||||
"include": ["src", "sandbox", "test"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue