1
Fork 0

typescript(option): test: wrote tests for filter

Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
Matei Adriel 2019-12-25 14:58:29 +02:00 committed by prescientmoon
parent 7e2e25263c
commit f8e501b876
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
3 changed files with 54 additions and 1 deletions

View 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)
})
})
})

View file

@ -1,2 +1,7 @@
import { Some } from '../src'
// general value to pass around // general value to pass around
export const x = Symbol('x') export const x = Symbol('x')
// same as x but for some
export const someX = Some(x)

View file

@ -8,5 +8,6 @@
"downlevelIteration": true, "downlevelIteration": true,
"target": "es6" "target": "es6"
}, },
"include": ["src", "sandbox", "test"] "include": ["src", "sandbox", "test"],
"exclude": ["dist"]
} }