AGENT SKILL

sinon-mocking

暂无简介

License 许可
MIT
最近更新
2026-06-24
Stars
★ 67
Forks
24

03 SKILL.md 正文

Sinon.js

Spies

const spy = sinon.spy(obj, 'method');
obj.method('arg');
expect(spy.calledWith('arg')).to.be.true;
spy.restore();

Stubs

const stub = sinon.stub(api, 'fetch');
stub.resolves({ id: 1, name: 'Alice' });
stub.withArgs('error').rejects(new Error('fail'));

Fake Timers

const clock = sinon.useFakeTimers();
const debounced = debounce(fn, 100);
debounced(); debounced();
clock.tick(100);
expect(fn.callCount).to.equal(1);
clock.restore();

Sandbox (auto-cleanup)

const sandbox = sinon.createSandbox();
afterEach(() => sandbox.restore());
sandbox.stub(api, 'fetch').resolves([]);

04 同仓库更多 Skills