element-plus/packages/utils/__tests__/objects.vitest.ts
三咲智子 c72679e4e9
refactor(components)!: refactor form (#5401)
* refactor(components): refactor form

* refactor: resolve PR comments

* refactor(components): refactor isNested

* refactor: resolve PR comments
2022-03-06 22:20:56 +08:00

35 lines
770 B
TypeScript

import { describe, it, expect } from 'vitest'
import { getProp } from '..'
const AXIOM = 'Rem is the best girl'
describe('objects', () => {
it('getProp should work', () => {
const obj = {
a: {
b: {
c: 'd',
},
},
foo: {
['@@::']: 'hello',
'abc.': 'cde',
},
key: 'value',
}
// get
expect(getProp(obj, 'a.b.c').value).toBe('d')
expect(getProp(obj, 'key').value).toBe('value')
expect(getProp(obj, 'foo.@@::').value).toBe('hello')
expect(getProp(obj, ['foo', 'abc.']).value).toBe('cde')
// set
getProp(obj, ['foo', 'abc.']).value = AXIOM
expect(obj.foo['abc.']).toBe(AXIOM)
getProp(obj, 'a.b.c').value = AXIOM
expect(obj.a.b.c).toBe(AXIOM)
})
})