Skip to content

Commit

Permalink
Specify default error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomek Wiszniewski committed Nov 19, 2015
1 parent 481c172 commit 5d3eade
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions test/flow-logic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,43 @@ test('rfx', nest => {
})('foo', 'bar', 'baz');
});

nest.test('...predicate rtype, dev env & default error handling', assert => {
assert.plan(3);

process.env.NODE_ENV = 'development';

const fx = rfx({
type () {
assert.pass('should type check');
return false;
},

fn () {
assert.fail('should not call fn');
}
});

try {
fx();
} catch (error) {
{
const actual = error.constructor;
const expected = TypeError;

assert.equal(actual, expected,
'should throw a TypeError');
}

{
const expectedContent = /wrong parameters.+predicate function/i;
const actualContent = error.message;

assert.ok(expectedContent.test(actualContent),
'should throw a descriptive error');
}
}
});

nest.test('...predicate rtype, prod env, onError & invalid args', assert => {
assert.plan(1);

Expand All @@ -58,6 +95,71 @@ test('rfx', nest => {
})('foo', 'bar', 'baz');
});

nest.test('...predicate rtype, prod env, default error handling', assert => {
assert.plan(2);

process.env.NODE_ENV = 'production';

const fx = rfx({
type () {
assert.fail('should not type check');
return false;
},

fn () {
assert.pass('should call fn');
}
});

assert.doesNotThrow(
() => fx(),
'should not throw an error'
);
});

nest.test('...predicate rtype, unknown env & onError', assert => {
assert.plan(3);

process.env.NODE_ENV = null;

rfx({
type () {
assert.pass('should type check');
return false;
},

fn () {
assert.pass('should call fn');
},

onError () {
assert.pass('should call onError');
}
})();
});

nest.test('...predicate rtype, unknown env & default error handling', assert => {
assert.plan(3);

process.env.NODE_ENV = null;

const fx = rfx({
type () {
assert.pass('should type check');
return false;
},

fn () {
assert.pass('should call fn');
}
});

assert.doesNotThrow(
() => fx(),
'should not throw an error'
);
});

nest.test('...predicate rtype, dev env, & no args', assert => {
process.env.NODE_ENV = 'development';

Expand Down

0 comments on commit 5d3eade

Please sign in to comment.