Download admin-bro/src/utils/flat/select-params.spec.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.53 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/admin-bro/src/utils/flat/select-params.spec.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@f5071caa249115f3b590492f1c8eb471e02aae4b/admin-bro/src/utils/flat/select-params.spec.ts
-
curl -L -o select-params.spec.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/admin-bro/src/utils/flat/select-params.spec.ts
1.53 kB
| 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() | |
| }) | |
| }) | |