UNPKG

cybernaut

Version:

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

138 lines 6.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const proxyquire = require("proxyquire"); const ava_1 = require("ava"); const description_1 = require("../description"); const stubs_1 = require("./stubs"); proxyquire.noPreserveCache(); proxyquire.preserveCache(); proxyquire('../predicate', { 'deep-strict-equal': stubs_1.predicateStubs.deepStrictEqual }); const predicate_1 = require("../predicate"); function createTestName(method) { return `\`PredicateBuilder.${method}\` should return a predicate`; } ava_1.default.beforeEach(() => { stubs_1.resetAll(stubs_1.predicateStubs); }); ava_1.default(createTestName('contain'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () { t.plan(5); const predicate = new predicate_1.PredicateBuilder().contain('foo'); t.is(description_1.format(predicate.description), 'should contain \'foo\''); t.true(predicate.test('foo')); t.true(predicate.test('foobar')); t.true(predicate.test('barfoo')); t.false(predicate.test('bar')); })); ava_1.default(createTestName('not.contain'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () { t.plan(5); const predicate = new predicate_1.PredicateBuilder().not.contain('foo'); t.is(description_1.format(predicate.description), 'should not contain \'foo\''); t.true(predicate.test('bar')); t.false(predicate.test('foo')); t.false(predicate.test('foobar')); t.false(predicate.test('barfoo')); })); ava_1.default(createTestName('equal'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () { t.plan(5); const predicate = new predicate_1.PredicateBuilder().equal('foo'); t.is(description_1.format(predicate.description), 'should equal \'foo\''); stubs_1.predicateStubs.deepStrictEqual.returns(true); t.true(predicate.test('bar')); t.is(stubs_1.predicateStubs.deepStrictEqual.callCount, 1); t.is(stubs_1.predicateStubs.deepStrictEqual.args[0][0], 'bar'); t.is(stubs_1.predicateStubs.deepStrictEqual.args[0][1], 'foo'); })); ava_1.default(createTestName('not.equal'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () { t.plan(5); const predicate = new predicate_1.PredicateBuilder().not.equal('foo'); t.is(description_1.format(predicate.description), 'should not equal \'foo\''); stubs_1.predicateStubs.deepStrictEqual.returns(true); t.false(predicate.test('bar')); t.is(stubs_1.predicateStubs.deepStrictEqual.callCount, 1); t.is(stubs_1.predicateStubs.deepStrictEqual.args[0][0], 'bar'); t.is(stubs_1.predicateStubs.deepStrictEqual.args[0][1], 'foo'); })); ava_1.default(createTestName('match'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () { t.plan(5); const predicate = new predicate_1.PredicateBuilder().match(/foo/); t.is(description_1.format(predicate.description), 'should match /foo/'); t.true(predicate.test('foo')); t.true(predicate.test('foobar')); t.true(predicate.test('barfoo')); t.false(predicate.test('bar')); })); ava_1.default(createTestName('not.match'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () { t.plan(5); const predicate = new predicate_1.PredicateBuilder().not.match(/foo/); t.is(description_1.format(predicate.description), 'should not match /foo/'); t.true(predicate.test('bar')); t.false(predicate.test('foo')); t.false(predicate.test('foobar')); t.false(predicate.test('barfoo')); })); ava_1.default(createTestName('be.above'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () { t.plan(4); const predicate = new predicate_1.PredicateBuilder().be.above(1); t.is(description_1.format(predicate.description), 'should be above 1'); t.true(predicate.test(2)); t.false(predicate.test(1)); t.false(predicate.test(0)); })); ava_1.default(createTestName('not.be.above'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () { t.plan(4); const predicate = new predicate_1.PredicateBuilder().not.be.above(1); t.is(description_1.format(predicate.description), 'should not be above 1'); t.true(predicate.test(0)); t.true(predicate.test(1)); t.false(predicate.test(2)); })); ava_1.default(createTestName('be.at.least'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () { t.plan(4); const predicate = new predicate_1.PredicateBuilder().be.at.least(1); t.is(description_1.format(predicate.description), 'should be at least 1'); t.true(predicate.test(2)); t.true(predicate.test(1)); t.false(predicate.test(0)); })); ava_1.default(createTestName('not.be.at.least'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () { t.plan(4); const predicate = new predicate_1.PredicateBuilder().not.be.at.least(1); t.is(description_1.format(predicate.description), 'should not be at least 1'); t.true(predicate.test(0)); t.false(predicate.test(1)); t.false(predicate.test(2)); })); ava_1.default(createTestName('be.below'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () { t.plan(4); const predicate = new predicate_1.PredicateBuilder().be.below(1); t.is(description_1.format(predicate.description), 'should be below 1'); t.true(predicate.test(0)); t.false(predicate.test(1)); t.false(predicate.test(2)); })); ava_1.default(createTestName('not.be.below'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () { t.plan(4); const predicate = new predicate_1.PredicateBuilder().not.be.below(1); t.is(description_1.format(predicate.description), 'should not be below 1'); t.true(predicate.test(2)); t.true(predicate.test(1)); t.false(predicate.test(0)); })); ava_1.default(createTestName('be.at.most'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () { t.plan(4); const predicate = new predicate_1.PredicateBuilder().be.at.most(1); t.is(description_1.format(predicate.description), 'should be at most 1'); t.true(predicate.test(0)); t.true(predicate.test(1)); t.false(predicate.test(2)); })); ava_1.default(createTestName('not.be.at.most'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () { t.plan(4); const predicate = new predicate_1.PredicateBuilder().not.be.at.most(1); t.is(description_1.format(predicate.description), 'should not be at most 1'); t.true(predicate.test(2)); t.false(predicate.test(1)); t.false(predicate.test(0)); })); //# sourceMappingURL=predicate.test.js.map