A read-only demo of every feature
Every page of this repository is open, and nothing can change. Take a guided tour of what TanStack Source does.
Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2import { addTask, completeTask, formatList, openTasks, progress, removeTask } from '../src/index.ts'
3
4describe('tasks', () => {
5 it('gives each new task the next id', () => {
6 const list = addTask(addTask([], 'Write the docs'), 'Ship it', 1)
7 expect(list.map((task) => task.id)).toEqual([1, 2])
8 })
9
10 it('refuses a task with no title', () => {
11 expect(() => addTask([], ' ')).toThrow('A task needs a title.')
12 })
13
14 it('refuses a negative priority', () => {
15 expect(() => addTask([], 'Docs', -1)).toThrow('A priority is 0 or more.')
16 })
17
18 it('lists the open tasks, the most important first', () => {
19 const list = completeTask(addTask(addTask(addTask([], 'Docs', 3), 'Fix the bug', 1), 'Done already', 2), 3)
20 expect(openTasks(list).map((task) => task.title)).toEqual(['Fix the bug', 'Docs'])
21 })
22
23 it('removes a task by id', () => {
24 expect(removeTask(addTask([], 'Docs'), 1)).toEqual([])
25 })
26})
27
28describe('format', () => {
29 it('writes Markdown checkboxes', () => {
30 const list = completeTask(addTask(addTask([], 'Ship it'), 'Docs'), 1)
31 expect(formatList(list)).toBe('- [x] Ship it\n- [ ] Docs')
32 })
33
34 it('counts progress as a whole percent', () => {
35 expect(progress([])).toBe(0)
36 expect(progress(completeTask(addTask(addTask(addTask([], 'a'), 'b'), 'c'), 1))).toBe(33)
37 })
38})