UNPKG

cybernaut

Version:

Reliable, zero configuration end-to-end testing in BDD-style.

55 lines 2.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const proxyquire = require("proxyquire"); const ava_1 = require("ava"); const stubs_1 = require("./stubs"); proxyquire.noPreserveCache(); proxyquire.preserveCache(); proxyquire('../step', { './utils': { sleep: stubs_1.stepStubs.sleep } }); const step_1 = require("../step"); ava_1.default.beforeEach(() => { stubs_1.resetAll(stubs_1.stepStubs); stubs_1.stepStubs.step.onFirstCall().rejects(new Error('foo')); stubs_1.stepStubs.step.onSecondCall().rejects(new Error('bar')); stubs_1.stepStubs.step.onThirdCall().resolves(undefined); }); ava_1.default('`run` should return 1', (t) => tslib_1.__awaiter(this, void 0, void 0, function* () { t.plan(3); stubs_1.stepStubs.step.onFirstCall().resolves(undefined); const attempts = yield step_1.run(stubs_1.stepStubs.step, 0, 0); t.is(attempts, 1); t.is(stubs_1.stepStubs.sleep.callCount, 0); t.is(stubs_1.stepStubs.step.callCount, attempts); })); ava_1.default('`run` should return 3', (t) => tslib_1.__awaiter(this, void 0, void 0, function* () { t.plan(5); const attempts = yield step_1.run(stubs_1.stepStubs.step, 2, 50); t.is(attempts, 3); t.is(stubs_1.stepStubs.sleep.callCount, 2); t.is(stubs_1.stepStubs.sleep.args[0][0], 50); t.is(stubs_1.stepStubs.sleep.args[1][0], 50); t.is(stubs_1.stepStubs.step.callCount, attempts); })); ava_1.default('`run` should throw an error with the message "foo"', (t) => tslib_1.__awaiter(this, void 0, void 0, function* () { t.plan(3); yield t.throws(step_1.run(stubs_1.stepStubs.step, 0, 50), 'foo'); t.is(stubs_1.stepStubs.sleep.callCount, 0); t.is(stubs_1.stepStubs.step.callCount, 1); })); ava_1.default('`run` should throw an error with the message "bar"', (t) => tslib_1.__awaiter(this, void 0, void 0, function* () { t.plan(4); yield t.throws(step_1.run(stubs_1.stepStubs.step, 1, 50), 'bar'); t.is(stubs_1.stepStubs.sleep.callCount, 1); t.is(stubs_1.stepStubs.sleep.args[0][0], 50); t.is(stubs_1.stepStubs.step.callCount, 2); })); ava_1.default('`run` should await `sleep`', (t) => tslib_1.__awaiter(this, void 0, void 0, function* () { t.plan(4); stubs_1.stepStubs.sleep.rejects(new Error('baz')); yield t.throws(step_1.run(stubs_1.stepStubs.step, 2, 50), 'baz'); t.is(stubs_1.stepStubs.sleep.callCount, 1); t.is(stubs_1.stepStubs.sleep.args[0][0], 50); t.is(stubs_1.stepStubs.step.callCount, 1); })); //# sourceMappingURL=step.test.js.map