Skip to content

Commit 806e4eb

Browse files
committedMar 28, 2018
➕ Add jest
1 parent c739935 commit 806e4eb

File tree

5 files changed

+3877
-5
lines changed

5 files changed

+3877
-5
lines changed
 

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules

‎package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "javascript-design-patterns",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"repository": "https://github.com/tangweikun/javascript-design-pattern.git",
6+
"author": "tangweikun <819573105@qq.com>",
7+
"license": "MIT",
8+
"scripts": {
9+
"watch": "jest --watch"
10+
},
11+
"babel": {
12+
"presets": ["es2015", "stage-2"]
13+
},
14+
"dependencies": {
15+
"babel-cli": "^6.26.0",
16+
"babel-core": "^6.26.0",
17+
"babel-jest": "^22.4.0",
18+
"babel-preset-env": "^1.6.1",
19+
"babel-preset-es2015": "^6.24.1",
20+
"babel-preset-stage-2": "^6.24.1",
21+
"jest": "^22.4.0",
22+
"regenerator-runtime": "^0.11.1"
23+
}
24+
}

‎src/creational/factory/simple-factory/UserFactory.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// 抽象产品角色 <Product>
22
function Admin() {
3-
console.log('Admin created!')
3+
return 'Admin created'
44
}
55
function Customer() {
6-
console.log('Customer created')
6+
return 'Customer created'
77
}
88

99
// 工厂角色 <Factory>
10-
const UserFactory = {}
10+
export const UserFactory = {}
1111
UserFactory.createUser = function(type) {
12-
if (type === 'admin') return new Admin()
13-
if (type === 'customer') return new Customer()
12+
if (type === 'admin') return Admin()
13+
if (type === 'customer') return Customer()
1414
}
1515

1616
// 具体产品角色 <ConcreteProduct>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { UserFactory } from '../UserFactory'
2+
3+
test('UserFactory-admin', () => {
4+
const admin = UserFactory.createUser('admin')
5+
expect(admin).toBe('Admin created')
6+
})
7+
8+
test('UserFactory-customer', () => {
9+
const customer = UserFactory.createUser('customer')
10+
expect(customer).toBe('Customer created')
11+
})

‎yarn.lock

Lines changed: 3836 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.