Topics
- Functional Programming in JavaScript
- Building a Modern JavaScript Library with Vite
- Unit Testing with Jest and Vitest
Resources
- đź“– Check out the handbook
- đź“ś Check out the slide
- đź’Ş Work in groups
- 🔨 Collaborate with Live Share
Workshop
The three rules of TDD
Robert C. Martin provides a concise set of rules for practicing Test-Driven Development. [?]
- You are not allowed to write any production code unless it is to make a failing unit test pass.
- You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures.
- You are not allowed to write any more production code than is sufficient to pass the one failing unit test.
Create test case for “filter” function
Create a filter.test.ts
file in modules
folder, and create a test case for filter
function.
1 | import { test, expect } from 'vitest'; |
Run test
command.
1 | npm run test |
Implement “filter” function
Update index.ts
file in modules
folder.
1 | // ... |
Create a filter.ts
file in modules
folder, and implement the filter
function.
1 | const filter = (items: Array<any>, callable: Function) => { |
Run test
command.
1 | npm run test |
Implement more functions
Implement more higher-order functions with TDD:
- map âś…
- filter âś…
- every
- find
- forEach
- reduce
- reject
- some
Finally, run coverage
command.
1 | npm run coverage |
Publish to NPM
Update index.ts
file in src
folder.
1 | export * from './modules'; |
Build the package before publishing.
1 | npm run build |
Login to NPM.
1 | npm login |
Update package.json
file.
1 | { |
Publish to NPM with dry run.
1 | npm publish --dry-run |
Publish to NPM.
1 | npm publish --access=public |