Skip to content

Commit 5a4c84c

Browse files
committed
pipe 에서 비동기 코드를 핸들링하는 테스트 추가, 이를 위한 babel 설정 추가
1 parent 68b4505 commit 5a4c84c

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

.babelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"plugins": [
3+
"transform-async-to-generator"
4+
]
5+
}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"test": "test"
88
},
99
"scripts": {
10-
"test": "mocha -R spec test/**/*.js"
10+
"test": "mocha -R spec --require babel-register test/**/*.js"
1111
},
1212
"repository": {
1313
"type": "git",
@@ -26,6 +26,9 @@
2626
},
2727
"homepage": "https://github.com/Functional-JavaScript/FunctionalES#readme",
2828
"devDependencies": {
29+
"babel-cli": "^6.26.0",
30+
"babel-plugin-transform-async-to-generator": "^6.24.1",
31+
"babel-register": "^6.26.0",
2932
"chai": "^4.1.2",
3033
"mocha": "^5.1.0"
3134
}

test/common.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe('[ curry2 ]', function () {
1919

2020
describe('[ pipe ]', function () {
2121
const add1 = a => a + 1
22+
const add1P = a => new Promise(resolve => setTimeout(() => resolve(a + 1), 1000))
2223
const mul2 = a => a * 2
2324

2425
it('pipe 는 인자로 받은 함수들을 순차적으로 실행하는 함수를 반환한다.', () => {
@@ -28,4 +29,20 @@ describe('[ pipe ]', function () {
2829
expect(f(1)).to.eql(4)
2930
expect(f(2)).to.eql(6)
3031
})
32+
33+
it('pipe 에 promise 를 반환하는 비동키 함수가 포함되는 경우 pipe 함수는 인자로 들어온 함수를 순차적으로 실행하지만 promise 를 반환한다.', async () => {
34+
this.timeout(2000)
35+
36+
const fP = pipe(add1P, mul2)
37+
expect(fP).to.be.a('function')
38+
39+
const p1 = fP(1)
40+
const p2 = fP(2)
41+
42+
expect(p1).to.be.a('Promise')
43+
expect(p2).to.be.a('Promise')
44+
45+
await p1.then(result => expect(result).to.eql(4))
46+
await p2.then(result => expect(result).to.eql(6))
47+
})
3148
})

0 commit comments

Comments
 (0)