Skip to content

Instantly share code, notes, and snippets.

@samjoch
Created August 24, 2020 06:55
Show Gist options
  • Save samjoch/dbe62556f20a3d6573ec3d08104b14b3 to your computer and use it in GitHub Desktop.
Save samjoch/dbe62556f20a3d6573ec3d08104b14b3 to your computer and use it in GitHub Desktop.
sinon sandbox and avajs
import ava, { TestInterface as TestI } from "ava";
import { createSandbox, SinonSandbox } from "sinon";
interface SinonContext {
sandbox: SinonSandbox;
}
export const test = ((test: TestI<SinonContext>): TestI<SinonContext> => {
test.beforeEach(t => {
t.context.sandbox = createSandbox();
});
test.afterEach(t => {
t.context.sandbox.restore();
});
return test;
})(ava);
// In your test:
// import { test } from './util';
// test("hello world", t => t.true(true))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment