base-ui
Version:
A component library for Better Vue developmemt
39 lines (33 loc) • 1.25 kB
JavaScript
import getValue from '../src/util/get-value';
test(`
input: record is { 'username': 'boluo' }, field is 'username', with default options ( needSplit is true ),
output: 'boluo'
`, () => {
const record = {username: 'boluo'};
const field = 'username';
expect(getValue(record, field)).toBe('boluo');
});
test(`
input: record is { 'user': { 'wechat': { 'openId': 'agt62' } } }, field is 'user.wechat.openId', with default options ( needSplit is true ),
output: 'agt62'
`, () => {
const record = {user: {wechat: {openId: 'agt62'}}};
const field = 'user.wechat.openId';
expect(getValue(record, field)).toBe('agt62');
});
test(`
input: record is { 'SUM(r.AMOUNT)': '171256.0000' }, field is 'SUM(r.AMOUNT)', with default options ( needSplit is true ),
output: null
`, () => {
const record = {'SUM(r.AMOUNT)': '171256.0000'};
const field = 'SUM(r.AMOUNT)';
expect(getValue(record, field)).toBe(null);
});
test(`
input: record is { 'SUM(r.AMOUNT)': '171256.0000' }, field is 'SUM(r.AMOUNT)', set options.needSplit to false,
output: 171256.0000
`, () => {
const record = {'SUM(r.AMOUNT)': '171256.0000'};
const field = 'SUM(r.AMOUNT)';
expect(getValue(record, field, {needSplit: false})).toBe('171256.0000');
});