UNPKG

luy

Version:

所谓类```React```框架就是**和React用法一模一样**的框架。其实当初制造这个框架的目的是为了能更好的学习React内部结构,了解其原理而制作的玩具。但是随着框架的渐渐成长,代码越来越多,我还是决定将其发展下去. ![](https://github.com/215566435/Luy/blob/master/luy%20icon2.jpg?raw=true)

39 lines (37 loc) 2.25 kB
import { flattenChildren } from '../app/src/Luy/createElement'; describe('flattenChildren', () => { describe('give flattenChildren an array', () => { it('[1,2,3,4,5,67,8,8]', () => { const ary = flattenChildren([1, 2, 3, 4, 5, 67, 8, 8]) expect(ary[0]).toEqual({ "key": null, "owner": null, "props": "123456788", "ref": null, "type": "#text" }) }); it('[1, 2, 3, { a: 4 }, 5, 67, 8, 8]', () => { const ary = flattenChildren([1, 2, 3, { a: 4 }, 5, 67, 8, 8]) expect(ary).toEqual([{ "key": null, "owner": null, "props": "123", "ref": null, "type": "#text" }, { "a": 4 }, { "key": null, "owner": null, "props": "56788", "ref": null, "type": "#text" }]) }); it('1asc', () => { const ary = flattenChildren('1asc') expect(ary).toEqual({ "key": null, "owner": null, "props": "1asc", "ref": null, "type": "#text" }, { "a": 4 }) }); it('[{a:123},2,3]', () => { const ary = flattenChildren([{a:123},2,3]) expect(ary).toEqual([{"a": 123}, {"key": null, "owner": null, "props": "23", "ref": null, "type": "#text"}]) }); it('[[1,2,3],"sss"]', () => { const ary = flattenChildren([[1,2,3],"sss"]) expect(ary).toEqual([1,2,3, {"key": null, "owner": null, "props": "sss", "ref": null, "type": "#text"}]) }); it('[[1,2,3],"sss",[1,2,3]]', () => { const ary = flattenChildren([[1,2,3],"sss",[1,2,3]]) expect(ary).toEqual([1,2,3, {"key": null, "owner": null, "props": "sss", "ref": null, "type": "#text"},1,2,3]) }); it('[[1,2,3],"sss","sss",[1,2,3]]', () => { const ary = flattenChildren([[1,2,3],"sss","sss",[1,2,3]]) expect(ary).toEqual([1,2,3, {"key": null, "owner": null, "props": "ssssss", "ref": null, "type": "#text"},1,2,3]) }); it('[[1,2,3],"sss",[1,2,3],"sss"]', () => { const ary = flattenChildren([[1,2,3],"sss",[1,2,3],"sss",]) expect(ary).toEqual([1,2,3, {"key": null, "owner": null, "props": "sss", "ref": null, "type": "#text"},1,2,3,{"key": null, "owner": null, "props": "sss", "ref": null, "type": "#text"}]) }); }); });