Skip to content
Myr

children.test.ts

This file

Path

src/jsx/children.test.ts

52 lines · 1.5 KiB · TypeScript

Last changed by

chore: let oxfmt sort imports instead of eslint (#5442)Yusuke Wadabefore adoption859e2c2

History of this file

Take it

The walk stopped after 200 commits: lines older than f0b094d point at it.

Merge commit from forkYusuke Wadabefore adoptionf0b094d

line 1why, one step back
1import { createElement } from '.'

chore: let oxfmt sort imports instead of eslint (#5442)Yusuke Wadabefore adoption859e2c2

line 2why, one step back
2import { Children } from './children'

Merge commit from forkYusuke Wadabefore adoptionf0b094d

lines 3–52why, one step back
3
4describe('map', () => {5 it('should map children', () => {6 const element = createElement('div', null, 1, 2, 3)7 const result = Children.map(element.children, (child) => (child as number) * 2)8 expect(result).toEqual([2, 4, 6])9 })10})1112describe('forEach', () => {13 it('should iterate children', () => {14 const element = createElement('div', null, 1, 2, 3)15 const result: number[] = []16 Children.forEach(element.children, (child) => {17 result.push(child as number)18 })19 expect(result).toEqual([1, 2, 3])20 })21})2223describe('count', () => {24 it('should count children', () => {25 const element = createElement('div', null, 1, 2, 3)26 const result = Children.count(element.children)27 expect(result).toBe(3)28 })29})3031describe('only', () => {32 it('should return the only child', () => {33 const element = createElement('div', null, 1)34 const result = Children.only(element.children)35 expect(result).toBe(1)36 })3738 it('should throw an error if there are multiple children', () => {39 const element = createElement('div', null, 1, 2)40 expect(() => Children.only(element.children)).toThrowError(41 'Children.only() expects only one child'42 )43 })44})4546describe('toArray', () => {47 it('should convert children to an array', () => {48 const element = createElement('div', null, 1, 2, 3)49 const result = Children.toArray(element.children)50 expect(result).toEqual([1, 2, 3])51 })52})