mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-28 10:14:13 +00:00
test(util) findObjByNameInArr
This commit is contained in:
parent
a8fafbf87b
commit
e0a656864e
1 changed files with 49 additions and 1 deletions
|
|
@ -5,7 +5,8 @@ const DIR = '../../';
|
|||
const Util = require(DIR + 'common/util');
|
||||
const {
|
||||
getStrBigFirst,
|
||||
kebabToCamelCase
|
||||
kebabToCamelCase,
|
||||
findObjByNameInArr,
|
||||
} = Util;
|
||||
|
||||
test('getExt: no extension', (t) => {
|
||||
|
|
@ -46,3 +47,50 @@ test('kebabToCamelCase', (t) => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('util: findObjByNameInArr: no array', (t) => {
|
||||
t.throws(findObjByNameInArr, /array should be array!/, 'should throw when no array');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('util: findObjByNameInArr: no name', (t) => {
|
||||
const fn = () => findObjByNameInArr([]);
|
||||
t.throws(fn, /name should be string!/, 'should throw when no name');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('util: findObjByNameInArr: object', (t) => {
|
||||
const name = 'hello';
|
||||
const obj = {
|
||||
name,
|
||||
};
|
||||
|
||||
const array = [
|
||||
obj,
|
||||
];
|
||||
|
||||
const result = findObjByNameInArr(array, name);
|
||||
|
||||
t.equal(result, obj, 'should return obj');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('util: findObjByNameInArr: array', (t) => {
|
||||
const name = 'hello';
|
||||
const data = 'abc';
|
||||
const item = {
|
||||
name,
|
||||
data,
|
||||
};
|
||||
|
||||
const array = [
|
||||
[
|
||||
item,
|
||||
]
|
||||
];
|
||||
|
||||
const result = findObjByNameInArr(array, name);
|
||||
|
||||
t.equal(result, data, 'should return data');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue