Skip to content

Instantly share code, notes, and snippets.

@pvdlg
Created December 17, 2018 16:56
Show Gist options
  • Save pvdlg/171b84eecd08b22da547c15c55a6163b to your computer and use it in GitHub Desktop.
Save pvdlg/171b84eecd08b22da547c15c55a6163b to your computer and use it in GitHub Desktop.
let state = 0;
console.log('Load module')
async function increment() {
state = state + 1;
}
function getState() {
return state;
}
module.exports = {increment, getState};
// This file should be in test/test.js
import test from 'ava';
import clearModule from 'clear-module';
test.beforeEach(t => {
clearModule('..');
t.context.m = require('..');
});
test('Test 1', async t => {
await t.context.m.increment();
t.is(t.context.m.getState(), 1);
});
test('Test 2', async t => {
await t.context.m.increment();
t.is(t.context.m.getState(), 1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment