How to use the ava.afterEach function in ava

To help you get started, we’ve selected a few ava examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github colombia-dev / leonel / test / invite.js View on Github external
createdAt
  }
  storage.users.get.callsArgWith(1, null, hostData)

  // export context
  t.context = {
    slack,
    guest,
    bot,
    message,
    createdAt,
    hostData
  }
})

test.afterEach(nock.cleanAll)

test('it sends new invitation', t => {
  t.plan(2)

  let { slack, bot, guest, message } = t.context
  slack.reply((uri, body, cb) => {
    let { email, token } = querystring.parse(body)

    t.is(email, guest, `email is ${email}`)
    t.is(token, process.env.SLACK_ADMIN_TOKEN, `token is ${token}`)
    cb(null, [200, { ok: true }])
  })

  // make invitation request
  return invite(bot, message)
})
github relekang / lint-filter / test / utils / git_tests.js View on Github external
import test from 'ava'
import sinon from 'sinon'
import Promise from 'bluebird'
import diffFixture from '../fixtures/diff'

import * as gitUtils from '../../src/utils/git'
import * as spawn from '../../src/utils/spawn'

test.beforeEach(t => {
  t.context.sandbox = sinon.sandbox.create() // eslint-disable-line no-param-reassign
})

test.afterEach(t => t.context.sandbox.restore())

test('parseDiffRanges(diff) should return empty array for no matches', t => {
  t.deepEqual(gitUtils.parseDiffRanges(''), [])
})

test('parseDiffRanges(diff) should return diff range for one match', t => {
  const diff = `
+++ b/src/gitUtils.js
@@ -0,0 +1,2 @@
+const exec = Promise.promisify(cp.exec)
+export function parseDiffRanges(diff) {
+const matches = diff.match(/\@\@ -\d+,\d+ \+(\d+),(\d+) \@\@/g)
  `
  t.deepEqual(gitUtils.parseDiffRanges(diff), [[1, 3]])
})
github openscope / openscope / test / aircraft / Pilot / clearedAsFiled.spec.js View on Github external
import _isObject from 'lodash/isObject';
import Pilot from '../../../src/assets/scripts/client/aircraft/Pilot/Pilot';
import {
    fmsArrivalFixture,
    modeControllerFixture
} from '../../fixtures/aircraftFixtures';
import {
    createNavigationLibraryFixture,
    resetNavigationLibraryFixture
} from '../../fixtures/navigationLibraryFixtures';

ava.beforeEach(() => {
    createNavigationLibraryFixture();
});

ava.afterEach(() => {
    resetNavigationLibraryFixture();
});

// TODO: Needs AircraftModel fixture, not just pilot
ava.skip('.clearedAsFiled() grants pilot departure clearance and returns the correct response strings', (t) => {
    const pilot = new Pilot(fmsArrivalFixture, modeControllerFixture);
    const result = pilot.clearedAsFiled();

    t.true(_isArray(result));
    t.true(result[0]);
    t.true(_isObject(result[1]));
    t.true(result[1].log === 'cleared to destination as filed');
    t.true(result[1].say === 'cleared to destination as filed');
    t.true(pilot.hasDepartureClearance);
});
github orionx-dev / orionx-sdk-js / test / queries / markets.js View on Github external
setOrionxCredentials()
})

test('Markets method returns markets', async t => {
  t.plan(2)
  try {
    const markets = await Orionx.markets()

    t.true(markets.length > 0)
    t.true(markets.filter(market => market.code === 'LTCBTC').length === 1)
  } catch (e) {
    t.fail(e.message)
  }
})

test.afterEach(async t => {
  await delay()
})
github OneSignal / OneSignal-Website-SDK / test / unit / public-sdk-apis / sendOutcome.ts View on Github external
const OUTCOME_NAME = "test_outcome";
const OUTCOME_WEIGHT = 55.6;

const sinonSandbox: SinonSandbox = sinon.sandbox.create();

test.beforeEach(async () => {
  await TestEnvironment.initialize();
  TestEnvironment.mockInternalOneSignal();

  const now = new Date().getTime();
  timemachine.config({
    timestamp: now,
  });
});

test.afterEach(() => {
  sinonSandbox.restore();
  timemachine.reset();
});

test("outcome name is required", async t => {
  const logSpy = sinonSandbox.stub(Log, "error");
  const apiSpy = sinonSandbox.stub(OneSignalApiShared, "sendOutcome").resolves();
  await (OneSignal as any).sendOutcome();
  t.is(logSpy.callCount, 1);
  t.is(apiSpy.callCount, 0);
});

test("outcome weight cannot be other than number or undefined", async t => {
  const logSpy = sinonSandbox.stub(Log, "error");
  const apiSpy = sinonSandbox.stub(OneSignalApiShared, "sendOutcome").resolves();
  await (OneSignal as any).sendOutcome(OUTCOME_NAME, {});
github openscope / openscope / test / aircraft / Pilot / initiateHoldingPattern.spec.js View on Github external
import {
    createNavigationLibraryFixture,
    resetNavigationLibraryFixture
} from '../../fixtures/navigationLibraryFixtures';

const holdParametersMock = {
    inboundHeading: -1.62476729292438,
    legLength: '1min',
    turnDirection: 'right'
};

ava.beforeEach(() => {
    createNavigationLibraryFixture();
});

ava.afterEach(() => {
    resetNavigationLibraryFixture();
});

ava('.initiateHoldingPattern() returns error response when specified fix is not in the route', (t) => {
    const expectedResult = [false, 'unable to hold at COWBY; it is not on our route!'];
    const pilot = new Pilot(fmsArrivalFixture, modeControllerFixture);
    const result = pilot.initiateHoldingPattern('COWBY', holdParametersMock);

    t.deepEqual(result, expectedResult);
});

ava('.initiateHoldingPattern() returns correct readback when hold implemented successfully', (t) => {
    const expectedResult = [true, 'hold east of KEPEC, right turns, 1min legs'];
    const pilot = new Pilot(fmsArrivalFixture, modeControllerFixture);
    const result = pilot.initiateHoldingPattern('KEPEC', holdParametersMock);
github openscope / openscope / test / engine / TimeKeeper.spec.js View on Github external
import ava from 'ava';
import TimeKeeper from '../../src/assets/scripts/client/engine/TimeKeeper';

ava.afterEach(() => {
    TimeKeeper.reset();
});

ava.serial('throws when attempting to instantiate', (t) => {
    t.throws(() => new TimeKeeper());
});

ava.serial('#deltaTime is the product of #_frameDeltaTime and #_simulationRate', (t) => {
    TimeKeeper._frameDeltaTime = 33;
    TimeKeeper._simulationRate = 1;

    t.true(TimeKeeper.deltaTime === 33);
});

ava.serial('#deltaTime returns a max value of 100', (t) => {
    TimeKeeper._frameDeltaTime = 33;
github tinajs / tina / test / cases / backward / component.js View on Github external
import '../../helpers/wx-globals'
import test from 'ava'
import sinon from 'sinon'

import MinaSandbox from '../../helpers/mina-sandbox'
import { objectify } from '../../helpers/functions'

import Tina from '../../..'

test.beforeEach((t) => {
  t.context.mina = new MinaSandbox({ Tina })
})
test.afterEach((t) => {
  t.context.mina.restore()
})

test.serial('`created`, `attached`, `ready`, `moved`, `detached` should be called', async (t) => {
  const options = {
    created: sinon.spy(),
    attached: sinon.spy(),
    ready: sinon.spy(),
    moved: sinon.spy(),
    detached: sinon.spy(),
    onNonexistentHook: sinon.spy(),
  }
  Tina.Component.define(options)

  const component = t.context.mina.getComponent(-1)
github tinajs / tina / test / cases / compute.js View on Github external
import '../helpers/wx-globals'
import test from 'ava'

import MinaSandbox from '../helpers/mina-sandbox'

import Tina from '../..'

test.beforeEach((t) => {
  t.context.mina = new MinaSandbox({ Tina })
})
test.afterEach((t) => {
  t.context.mina.restore()
})

test.serial('`compute` should be called and merged with `data` by Page', async (t) => {
  const options = {
    data: {
      foo: 'bar',
    },
    compute (state) {
      return {
        foobar: state.foo + 'baz',
      }
    },
  }
  Tina.Page.define(options)
github notonthehighstreet / breadboard / spec / lib / getAppModules.spec.js View on Github external
name: chance.word()
};
let subject;
let fakeContainerRoot;
let fakeWalkerDir;

test.beforeEach(() => {
  fakeWalkerDir = chance.word();
  walkerStub.on.withArgs('file').yields(fakeWalkerDir, fakeFileStat, () => {
  });
  mock('walk', walkMock);
  mock('../../lib/getModuleKey', getModuleKeyMock);
  fakeContainerRoot = chance.word();
  subject = require('../../lib/getAppModules');
});
test.afterEach(() => {
  mock.stopAll();
  sandbox.reset();
});

test('throws if container root not specified', t => {
  t.throws(subject());
});
test('creates a directory walker', t => {
  subject(fakeContainerRoot);
  t.truthy(walkMock.walk.calledWithExactly(fakeContainerRoot));
});
test('does not throw when no substitutes defined', t => {
  t.notThrows(() => {
    subject(fakeContainerRoot);
  });
});