๋ฌธ์ ๋น :
[email protected]_ ์ดํ
sinon.resetHistory ()๋ฅผ ์ฌ์ฉํ์ฌ ๋ชจ๋ ์คํ ์ ํ์คํ ๋ฆฌ๋ฅผ ์ฌ์ค์ ํ ์ ์์ต๋๋ค.
์ฌํํ๋ ค๋ฉด
const assert = require('chai').assert;
const sinon = require('sinon');
describe('resetHistory', function() {
var num = null;
beforeEach(function() {
num = sinon.createStubInstance(Number);
});
afterEach(() => {
// Restore the default sandbox here
sinon.restore();
});
describe('called on individual stub method', function() {
it('should clear "called" status on stub', function() {
num.toFixed();
assert.isTrue(num.toFixed.called);
num.toFixed.resetHistory();
assert.isFalse(num.toFixed.called);
});
});
describe('called on module', function() {
it('should clear "called" status on all stubs', function() {
num.toFixed();
assert.isTrue(num.toFixed.called);
sinon.resetHistory();
assert.isFalse(num.toFixed.called);
});
});
});
์ค์ ๊ฒฐ๊ณผ
๋ ๋ฒ์งธ ํ
์คํธ ์คํจ :
""called on module : ๋ชจ๋ ์คํ
์์ \ "called \"์ํ๋ฅผ ์ง์์ผํฉ๋๋ค. โ. [assert.isFalse] true๊ฐ false ์ฌ์ผํฉ๋๋ค. ""
์์ ๊ฒฐ๊ณผ
๋ชจ๋ ํ ์คํธ ํต๊ณผ
zip ํ์ผ์ ๋ด์ฉ์ผ๋ก ๋ฌธ์ ๋ฅผ ์ ๋ฐ์ดํธํ๊ณ ์คํ ๊ฐ๋ฅํ RunKit ๋ฐ๋ชจ ๋ก ์ถ๊ฐํ์ฌ ์๋ํ๋ค๊ณ ์ฃผ์ฅํ์ต๋๋ค.
๋ฒ๊ทธ ์์ ์ ๋๊ณ ์ถ์ต๋๋ค
@rpgeeganage ์ ๋ฐํ์ธ์! ์์ ๊ฐ์ด๋ ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
์ด ์ฃผ์์ด ๊ธฐ๋ฅ ์์ฒญ์ ๋ ๊ฐ๊น๋ค๋ ๊ฒ์ ์๊ณ ์์ง๋ง "stub instance"๊ฐ์ฒด์ ์์ฒด resetHistory()
(๋ฐ resetBehavior()
๋ฐ reset()
) ๋ฉ์๋๊ฐ ์์ผ๋ฉด ์ข์ ๊ฒ์
๋๋ค. ์๋ ๋ฐ์ค ์ ์ฒด๋ฅผ ์น์ง ์์๋๋ฉ๋๋ค.
@mcow ์๋ํด ๋ณด์ จ์ต๋๊น? ๐ ์คํ ์ Sinon ๋ฒ์ 2๋ถํฐ ์ด๋ฌํ ๊ธฐ๋ฅ ์
@ fatso83 ,
๊ฐ์ฌํฉ๋๋ค. ๋ด๊ฐ ์์
ํ ๊ฒ.
@ fatso83 ์คํ
๋ฉ์๋ ์๋ ํด๋น ๊ธฐ๋ฅ์ด ์์ต๋๋ค. "Stub instance"๊ฐ์ฒด , createStubInstance()
ํธ์ถ์ ๊ฒฐ๊ณผ (๋ถ๋ช
ํ ํ ์ฉ์ด๋ sinon, ์๋ชป๋ ์์ฌ ์ํต์ ๋ํด ๋๋ฅผ ๋น๋ํ์ง ๋ง์ญ์์ค).
@ fatso83 ,
sinon.resetHistory
๋ฐ sinon.createStubInstance
.
๋ด๊ฐ ์์ ์ฐจ๋ฆฐ ๊ฒ์ sinon.createStubInstance
๋ sandbox
์ ๊ตฌํ์ ์ฌ์ฉํ์ง ์์ง๋ง sinon.resetHistory
๋ sandbox
์ ๊ตฌํ์ ์ฌ์ฉํ๋ค๋ ๊ฒ์
๋๋ค. sinon.resetHistory
์์ collection
๋ ํญ์ ๋น์ด ์์ต๋๋ค. ๋๋ ๊น์ด ํํค์น ๊ฒ์ด๋ค.
@mcow Aha, ์ค๋ช ํฉ๋๋ค. ๋๋ _instance_ ๋นํธ๋ฅผ ์์ ์ฐจ๋ฆฌ์ง ๋ชปํ๋ค. :) ๋ฐ๋ผ๊ฑด๋
@ fatso83 , ๋ณ๊ฒฝ ์ฌํญ์ด ๋ง์คํฐ์ ๋ณํฉ
๊ธฐ๋ฏผํ ๊ด์ฐฐ์๋ฅผ์ํ TG ๐