|
1 |
| -test('ssr: renderList', () => { |
2 |
| - // TODO |
| 1 | +import { ssrRenderList } from '../src/helpers/ssrRenderList' |
| 2 | + |
| 3 | +describe('ssr: renderList', () => { |
| 4 | + let stack: string[] = [] |
| 5 | + |
| 6 | + beforeEach(() => { |
| 7 | + stack = [] |
| 8 | + }) |
| 9 | + |
| 10 | + it('should render items in an array', () => { |
| 11 | + ssrRenderList(['1', '2', '3'], (item, index) => |
| 12 | + stack.push(`node ${index}: ${item}`) |
| 13 | + ) |
| 14 | + expect(stack).toEqual(['node 0: 1', 'node 1: 2', 'node 2: 3']) |
| 15 | + }) |
| 16 | + |
| 17 | + it('should render characters of a string', () => { |
| 18 | + ssrRenderList('abc', (item, index) => stack.push(`node ${index}: ${item}`)) |
| 19 | + expect(stack).toEqual(['node 0: a', 'node 1: b', 'node 2: c']) |
| 20 | + }) |
| 21 | + |
| 22 | + it('should render integers 1 through N when given a number N', () => { |
| 23 | + ssrRenderList(3, (item, index) => stack.push(`node ${index}: ${item}`)) |
| 24 | + expect(stack).toEqual(['node 0: 1', 'node 1: 2', 'node 2: 3']) |
| 25 | + }) |
| 26 | + |
| 27 | + it('should render properties in an object', () => { |
| 28 | + ssrRenderList({ a: 1, b: 2, c: 3 }, (item, key, index) => |
| 29 | + stack.push(`node ${index}/${key}: ${item}`) |
| 30 | + ) |
| 31 | + expect(stack).toEqual(['node 0/a: 1', 'node 1/b: 2', 'node 2/c: 3']) |
| 32 | + }) |
| 33 | + |
| 34 | + it('should render an item for entry in an iterable', () => { |
| 35 | + const iterable = function*() { |
| 36 | + yield 1 |
| 37 | + yield 2 |
| 38 | + yield 3 |
| 39 | + } |
| 40 | + |
| 41 | + ssrRenderList(iterable(), (item, index) => |
| 42 | + stack.push(`node ${index}: ${item}`) |
| 43 | + ) |
| 44 | + expect(stack).toEqual(['node 0: 1', 'node 1: 2', 'node 2: 3']) |
| 45 | + }) |
| 46 | + |
| 47 | + it('should not render items when source is undefined', () => { |
| 48 | + ssrRenderList(undefined, (item, index) => |
| 49 | + stack.push(`node ${index}: ${item}`) |
| 50 | + ) |
| 51 | + expect(stack).toEqual([]) |
| 52 | + }) |
3 | 53 | })
|
0 commit comments