File size: 1,530 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
import { expect } from 'chai'
import { selectParams } from './select-params.js'
describe('selectParams', () => {
const params = {
name: 'John',
surname: 'Doe',
age: 31,
'meta.description': 'very ugly',
'meta.title': 'cto',
'meta.otherInfo': 'he stinks',
metadetaksamosone: 'this is a steroid',
}
it('selects params for given property', () => {
expect(selectParams(params, 'age')).to.deep.equal({
age: 31,
})
})
it('select params for nested property', () => {
expect(selectParams(params, 'meta')).to.deep.equal({
'meta.description': 'very ugly',
'meta.title': 'cto',
'meta.otherInfo': 'he stinks',
})
})
it('returns empty object when there is no match', () => {
expect(selectParams(params, 'nothingIsThere')).to.deep.eq({})
})
it('returns multiple properties when they are given', () => {
expect(selectParams(params, ['name', 'surname'])).to.deep.equal({
name: 'John',
surname: 'Doe',
})
})
it('does not one property when is empty for multi-properties', () => {
expect(selectParams(params, ['name', 'surname', 'meta', 'empty'])).to.deep.equal({
name: 'John',
surname: 'Doe',
'meta.description': 'very ugly',
'meta.title': 'cto',
'meta.otherInfo': 'he stinks',
})
})
it('does not throw an error when user passes undefined as a propertyPath', () => {
expect(() => {
selectParams(params, ['name', undefined as unknown as string])
}).not.to.throw()
})
})
|