Skip to content

Commit 6f0b6f9

Browse files
committed
curry2 & pipe 에 함수가 아닌 값을 인자로 넣었을 때 발생할 수 있는 에러에 대한 테스트 추가
1 parent 5a4c84c commit 6f0b6f9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/common.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ describe('[ curry2 ]', function () {
1515
expect(addWith5(3)).to.eql(8)
1616
expect(addWith5(5)).to.eql(10)
1717
})
18+
19+
it('curry2 에 함수가 아닌 인자를 입력하는 경우 TypeError 가 발생할 수 있다.', () => {
20+
const unknown = curry2('abc')
21+
22+
expect(unknown).to.be.a('function')
23+
expect(unknown(1)).to.be.a('function')
24+
expect(() => unknown(1)(2)).to.throw(TypeError, 'Function.prototype.apply was called on abc, which is a string and not a function')
25+
unknown(1)(2)
26+
})
1827
})
1928

2029
describe('[ pipe ]', function () {
@@ -45,4 +54,13 @@ describe('[ pipe ]', function () {
4554
await p1.then(result => expect(result).to.eql(4))
4655
await p2.then(result => expect(result).to.eql(6))
4756
})
57+
58+
it('pipe 중간에 함수가 아닌 인자가 들어가는 경우 TypeError 가 발생할 수 있다.', () => {
59+
const f = pipe(add1, mul2, 3)
60+
61+
expect(f).to.be.a('function')
62+
expect(() => f(1)).to.throw(TypeError, 'f is not a function')
63+
expect(() => f(2)).to.throw(TypeError, 'f is not a function')
64+
f(1)
65+
})
4866
})

0 commit comments

Comments
 (0)