Skip to content

Commit e5d5896

Browse files
committed
Initial commit with several TDD TypeScript examples
0 parents  commit e5d5896

39 files changed

+8844
-0
lines changed

.gitignore

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
78+
# Next.js build output
79+
.next
80+
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
dist
84+
85+
# Gatsby files
86+
.cache/
87+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88+
# https://nextjs.org/blog/next-9-1#public-directory-support
89+
# public
90+
91+
# vuepress build output
92+
.vuepress/dist
93+
94+
# Serverless directories
95+
.serverless/
96+
97+
# FuseBox cache
98+
.fusebox/
99+
100+
# DynamoDB Local files
101+
.dynamodb/
102+
103+
# TernJS port file
104+
.tern-port

.prettierignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# compiled output
2+
/bin
3+
/dist
4+
/tmp
5+
/out-tsc
6+
7+
# dependencies
8+
/node_modules
9+
10+
# misc
11+
/.sass-cache
12+
/connect.lock
13+
/coverage
14+
npm-debug.log
15+
yarn-error.log
16+
/typings
17+
18+
# misc
19+
/.sass-cache
20+
/connect.lock
21+
/coverage
22+
npm-debug.log
23+
yarn-error.log
24+
testem.log
25+
/typings

.prettierrc.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"arrowParens": "avoid",
3+
"bracketSpacing": true,
4+
"jsxBracketSameLine": true,
5+
"printWidth": 80,
6+
"proseWrap": "preserve",
7+
"semi": true,
8+
"singleQuote": true,
9+
"tabWidth": 2,
10+
"trailingComma": "es5",
11+
"useTabs": false
12+
}

.vscode/extensions.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"recommendations": [
3+
"esbenp.prettier-vscode",
4+
"dbaeumer.vscode-eslint",
5+
"pkief.material-icon-theme",
6+
"christian-kohler.path-intellisense",
7+
"streetsidesoftware.code-spell-checker"
8+
]
9+
}

.vscode/settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"[javascript]": {
3+
"editor.defaultFormatter": "esbenp.prettier-vscode"
4+
},
5+
"[typescript]": {
6+
"editor.defaultFormatter": "esbenp.prettier-vscode"
7+
},
8+
"editor.formatOnSave": true,
9+
"editor.defaultFormatter": "esbenp.prettier-vscode",
10+
"editor.formatOnType": true,
11+
"typescript.format.insertSpaceAfterTypeAssertion": true,
12+
"cSpell.words": ["codepaths", "Fizzbuzz", "tsbuildinfo"]
13+
}

.vscode/ts-jst-snippets.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"Jest Describe It": {
3+
"prefix": "ab-jst-dit",
4+
"body": [
5+
"describe('$1', () => {",
6+
" let sut;",
7+
" beforeEach(() => {",
8+
" // Arrange",
9+
" sut = null;",
10+
" });",
11+
" it('should $2', () => {",
12+
" // Act",
13+
" const actual = null;",
14+
" // Assert",
15+
" const expected = null;",
16+
" expect(actual).toStrictEqual(expected);",
17+
" });",
18+
"});"
19+
],
20+
"description": "Describe It Should with Jest"
21+
},
22+
"Jest It": {
23+
"prefix": "ab-jst-it",
24+
"body": [
25+
"it('should $2', () => {",
26+
" const sut = null;",
27+
" const actual = null;",
28+
" const expected = null;",
29+
" expect(actual).toBe(expected);",
30+
"});"
31+
],
32+
"description": "It Should with Jest"
33+
}
34+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Juan Jesús Gómez Noya
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# tdd-typescript-jest
2+
3+
Test driven development with Jest and Typescript
4+
5+
```bash
6+
# Git clone and use as is
7+
git clone https://github.com/burus86/tdd-typescript-jest.git
8+
cd tdd-typescript-jest
9+
npm i
10+
npm test
11+
12+
# Alternatively, start from empty folder
13+
14+
npm i -D typescript jest
15+
npm i -D @types/node @types/jest
16+
npm i -D ts-jest
17+
npx ts-jest config:init
18+
npx tsc --init
19+
```

docs/0-intro-tdd.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# 0 - Intro TDD
2+
3+
## TDD is testing
4+
5+
### Tools: Jest
6+
7+
- Test runner
8+
- Assertion library
9+
- Testing framework
10+
11+
### Syntax
12+
13+
```ts
14+
describe('the subject under test', () => {
15+
let sut;
16+
beforeEach(() => {
17+
// Arrange
18+
sut = undefined;
19+
});
20+
it('should do something', () => {
21+
// Act
22+
const actual = undefined;
23+
// Assert
24+
const expected = undefined;
25+
expect(actual).toStrictEqual(expected);
26+
});
27+
});
28+
```
29+
30+
## TDD is a coding discipline
31+
32+
### Test before
33+
34+
- If you write your tests before you are forced to think and have a better understanding.
35+
- If you write your tests before you will have a functional documentation for free.
36+
- If you write your tests before your objects wil have a more convenient API.
37+
- If you write your tests before your code will be easier to maintain.
38+
- If you write your tests before... you always write tests.
39+
40+
### Red Green Refactor
41+
42+
- ❌ Red: Write a test and see it failing
43+
- ✔️ Green: Write the minimum code that makes the test pass
44+
- 🔵 Refactor: Write a cleaner or more efficient implementation
45+
46+
> 🚧 Some people considere a yellow step when test does not compile yet
47+
48+
### Unit, integration, e2e
49+
50+
- Can be used for any kind of tests... but
51+
- In my opinion TDD is better suited to unit testing complex clases or functions
52+
53+
## TDD timings
54+
55+
- Initially it takes longer to get things done
56+
- Reduces debugging times in the medium term
57+
- Start small and take baby steps
58+
- Test should be really fast

docs/1-tdd-sources.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# 1 - TDD sources
2+
3+
## From explicit rules
4+
5+
- Easiest scenario
6+
- Test each rule with samples
7+
8+
## From examples
9+
10+
- Could be hard or at least time consuming
11+
- The algorithm emerges providing more and more samples
12+
13+
## From vague requirements
14+
15+
- Not desiderable but common
16+
- Forces you to ask more detailed questions

docs/2-tdd-domains.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# 2 - TDD domains
2+
3+
## The core knowledge
4+
5+
- What it is important
6+
7+
## A description of the real world
8+
9+
- Higher level rules, not implementation details
10+
11+
## Incremental value
12+
13+
- Evolving functionality and solving issues

jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
};

0 commit comments

Comments
 (0)