Test migration to jest by hand
Apparently using regular expressions is way easier.
This commit is contained in:
9
test/get/get.js
Normal file
9
test/get/get.js
Normal file
@ -0,0 +1,9 @@
|
||||
const get = (from, ...selectors) =>
|
||||
[...selectors].map(s =>
|
||||
s
|
||||
.replace(/\[([^\[\]]*)\]/g, '.$1.')
|
||||
.split('.')
|
||||
.filter(t => t !== '')
|
||||
.reduce((prev, cur) => prev && prev[cur], from)
|
||||
);
|
||||
module.exports = get;
|
||||
11
test/get/get.test.js
Normal file
11
test/get/get.test.js
Normal file
@ -0,0 +1,11 @@
|
||||
const expect = require('expect');
|
||||
const get = require('./get.js');
|
||||
|
||||
|
||||
test('get is a Function', () => {
|
||||
expect(get).toBeInstanceOf(Function);
|
||||
});
|
||||
const obj = { selector: { to: { val: 'val to get' } } };
|
||||
t.deepEqual(get(obj, 'selector.to.val'), ['val to get'], "Retrieve a property indicated by the selector from an object.");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user