Sinon: μŠ€ν…μ—λŠ” 약속 κ²°κ³Όλ₯Ό μ„€μ •ν•˜κΈ°μœ„ν•œ`resolves` 및`rejects`κ°€ μžˆμ–΄μ•Όν•©λ‹ˆλ‹€.

에 λ§Œλ“  2015λ…„ 08μ›” 08일  Β·  13μ½”λ©˜νŠΈ  Β·  좜처: sinonjs/sinon

이것은 맀우 κ°„λ‹¨ν•œ ꡬ문 μ„€νƒ•μž…λ‹ˆλ‹€.

var stub = sinon.stub();
stub.resolves("hello");
//is the same as
stub.returns(Promise.resolve("hello"));

stub.rejects(new Error("oh noes!"));
//is the same as
stub.returns(Promise.reject(new Error("oh noes!"));
Medium Feature Request Help wanted

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

μŠ€ν…μ΄ promiseλ₯Ό λ°˜ν™˜ν•˜λŠ” sinon.stub().returnsArg(1) μˆ˜ν–‰ ν•  수 μžˆμŠ΅λ‹ˆκΉŒ? λ‚˜λŠ” μ•½μ†μ˜ 결의둜 λ…ΌμŸμ„ 되돌리렀 κ³  λ…Έλ ₯ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€. μž‘λ™ν•˜μ§€ μ•ŠλŠ” 것 κ°™μŠ΅λ‹ˆλ‹€.

λͺ¨λ“  13 λŒ“κΈ€

그것은 쒋은 섀탕이 될 κ²ƒμž…λ‹ˆλ‹€. @mariusGundersen을 μ œμ•ˆ

- 우리 νŒ€μ€ 이런 μ’…λ₯˜μ˜ 우리λ₯Ό λ•κ³ μžˆλ‹€ NPM에 μž‘μ€ λ„μ„œκ΄€μ΄ https://github.com/substantial/sinon-stub-promise : -이 같은 μŠ€ν… ꡬ문 μš”κ΅¬κ°€ ν˜„μž¬ κ΅¬ν˜„μžˆμ–΄ κΈΈ μžˆμ§€λ§Œ sinon.stub().returnsPromise() . 생각? μœ„μ˜ μ˜ˆμ—μ„œ 이것은 동기 평가λ₯Ό κ°€μ •ν•˜λŠ” κ²ƒμ²˜λŸΌ λ³΄μž…λ‹ˆλ‹€.

@mariusGundersen 의 μ œμ•ˆμ„ 정말 μ’‹μ•„ν•©λ‹ˆλ‹€. λ‚΄κ°€ μ•„λŠ” ν•œ λͺ¨λ“  promise λΌμ΄λΈŒλŸ¬λ¦¬λŠ” 항상 비동기 μ μž…λ‹ˆλ‹€. κ·Έλ ‡λ‹€λ©΄ μŠ€ν… 약속이이 λ™μž‘μ„ λ°˜μ˜ν•΄μ•Όν•œλ‹€κ³  μƒκ°ν•©λ‹ˆλ‹€.

λ‚˜λŠ” 그것이 μ‘΄μž¬ν•œλ‹€λ©΄ μ „ μ„Έκ³„μ μœΌλ‘œ μ‚¬μš© κ°€λŠ₯ν•œ Promise.resolve ν•˜κ³  그렇지 μ•ŠμœΌλ©΄ μž‘λ™ν•˜μ§€ μ•Šμ„ 것이라고 μƒκ°ν–ˆμŠ΅λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ then λ©”μ„œλ“œλ₯Ό μ‚¬μš©ν•˜μ—¬ 개체λ₯Ό λ°˜ν™˜ν•˜λ„λ‘ν•˜λŠ” 것이 훨씬 더 λ‚˜μ€ μ†”λ£¨μ…˜μž…λ‹ˆλ‹€.

var stub = sinon.stub(); 
stub.resolves("hello"); 
//is the same as 
stub.returns({then: x => setTimeout(()  => x("hello"), 0)}); 
stub.rejects(new Error("oh noes!")); 
//is the same as 
stub.returns({then: x => undefined, catch: x => setTimeout(() => x(new Error("oh noes!")), 0)});

(μ „ν™”λ‘œ μž‘μ„±, 였λ₯˜κ°€μžˆμ„ 수 있음)

우리 νŒ€μ€ μœ μ‚¬ν•œ κΈ°λŠ₯을 μ œκ³΅ν•˜κΈ° μœ„ν•΄ μ•½κ°„μ˜ libλ₯Ό μž‘μ„±ν–ˆμŠ΅λ‹ˆλ‹€. μ•„λ§ˆλ„ 이것이 도움이 될 κ²ƒμž…λ‹ˆλ‹€. Promiseλ₯Ό μœ„ν•΄ bluebird 라이브러리λ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€. https://www.npmjs.com/package/sinon-bluebird

λ„€μ΄ν‹°λΈŒ Promise μ§€μ›μ„μœ„ν•œ +1

λ˜ν•œ μŠ€ν„°λΈŒμ— 해석 / κ±°λΆ€ 의미λ₯Ό μΆ”κ°€ν•˜κΈ° μœ„ν•΄ native-promise-only λ₯Ό μ‚¬μš©ν•˜μ—¬ ν”„λ‘œμ νŠΈμ˜ κΈ°μ‘΄ sinon λͺ¨λ“ˆμ„ 패치 ν•˜λŠ” sinon-as-promised λΌλŠ” ν”„λ‘œμ νŠΈκ°€ μžˆμŠ΅λ‹ˆλ‹€.

이것이 λ˜λŠ” λ‹€λ₯Έ λͺ¨λ“ˆ 쀑 ν•˜λ‚˜μ˜ λ³€κ²½ 사항이 sinon μžμ²΄μ— μΆ”κ°€ 될 수 μžˆλ‹€λ©΄ μ—μ΄μŠ€κ°€ 될 κ²ƒμž…λ‹ˆλ‹€.

μŠ€ν…μ΄ promiseλ₯Ό λ°˜ν™˜ν•˜λŠ” sinon.stub().returnsArg(1) μˆ˜ν–‰ ν•  수 μžˆμŠ΅λ‹ˆκΉŒ? λ‚˜λŠ” μ•½μ†μ˜ 결의둜 λ…ΌμŸμ„ 되돌리렀 κ³  λ…Έλ ₯ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€. μž‘λ™ν•˜μ§€ μ•ŠλŠ” 것 κ°™μŠ΅λ‹ˆλ‹€.

@jnystrom μ‚¬μš©λ²• μ§ˆλ¬Έμ€ 메일 λ§λ¦¬μŠ€νŠΈμ— μ†ν•˜μ§€λ§Œ sinon이 ν˜„μž¬ ꡬ문 μ„€νƒ•μœΌλ‘œ μ§€μ›ν•˜λŠ” 것은 μ•„λ‹™λ‹ˆλ‹€. ꡬ문을 μ œμ•ˆ ν•  수 μžˆμŠ΅λ‹ˆκΉŒ? 이와 같은 것은 당신이 μ›ν•˜λŠ” κ²ƒμ„ν•΄μ•Όν•˜λ©° 당신은 그것을 μœ„ν•΄ sinon이 ν•„μš”ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

stub = (arg) => Promise.resolve(arg);

μ—¬κΈ°μ—μ„œλ„ 동일 : # 738

μ•ˆλ…•ν•˜μ„Έμš” μ—¬λŸ¬λΆ„, λ¨Όμ € Sinonμ—μ„œ ν›Œλ₯­ν•œ μž‘μ—…μ„ ν•΄μ£Όμ…”μ„œ κ°μ‚¬ν•©λ‹ˆλ‹€.
이 κΈ°λŠ₯을 κ΅¬ν˜„ν•˜κ³  μ‹Άλ‹€λ©΄ 저도 μ‹œλ„ν•΄λ³΄κ³  μ‹ΆμŠ΅λ‹ˆλ‹€. μ•Œλ € μ£Όμ‹œλ©΄ PR μž‘μ—…μ„ μ‹œμž‘ν•˜κ² μŠ΅λ‹ˆλ‹€.

@lucasfcosta , κ°μ‚¬ν•©λ‹ˆλ‹€. μ €λŠ” @mroderick이 sinon-as-promised λ₯Ό Sinon에 ν†΅ν•©ν•˜λŠ” 것에 λŒ€ν•΄ 였래 전에 μ΄μ•ΌκΈ°ν–ˆλ‹€κ³  μƒκ°ν•©λ‹ˆλ‹€. 그렇지 μ•ŠμŠ΅λ‹ˆκΉŒ? 그것이 κ°€μž₯ μ‰¬μš΄ 해결책이 될 것이고, μ €λŠ” μ΄μ˜κ°€ μ—†μŠ΅λ‹ˆλ‹€.

@lucasfcosta μ €λŠ” sinon-as-promised λ₯Ό Sinon의 master 지점에 ν†΅ν•©ν•˜λŠ” PR을보고 μ‹ΆμŠ΅λ‹ˆλ‹€.

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰