conditional
Version:
A preconditions package based on Google's Preconditions library
61 lines (56 loc) • 1.93 kB
JavaScript
(function() {
var IllegalValueError, checkNotEmpty;
require('./helpers/test_helper');
checkNotEmpty = preconditions.checkNotEmpty, IllegalValueError = preconditions.IllegalValueError;
describe('test notEmpty precondition', function() {
it('null is a empty value', function() {
var wrapper;
wrapper = function() {
return checkNotEmpty(null, 'should not be null');
};
return assert.throws(wrapper, IllegalValueError, 'should not be null');
});
it('undefined is a empty value', function() {
var wrapper;
wrapper = function() {
return checkNotEmpty({}.x, 'should not be undefined');
};
return assert.throws(wrapper, IllegalValueError, 'should not be undefined');
});
it('empty array is a empty value', function() {
var wrapper;
wrapper = function() {
return checkNotEmpty([], 'should not be empty');
};
return assert.throws(wrapper, IllegalValueError, 'should not be empty');
});
it('empty object is a empty value', function() {
var wrapper;
wrapper = function() {
return checkNotEmpty({}, 'should not be empty');
};
return assert.throws(wrapper, IllegalValueError, 'should not be empty');
});
it('empty string is a empty value', function() {
var wrapper;
wrapper = function() {
return checkNotEmpty('', 'should not be empty');
};
return assert.throws(wrapper, IllegalValueError, 'should not be empty');
});
it('0 (zero) is not empty', function() {
var wrapper;
wrapper = function() {
return checkNotEmpty(0);
};
return assert.doesNotThrow(wrapper);
});
return it('boolean false is not empty', function() {
var wrapper;
wrapper = function() {
return checkNotEmpty(false);
};
return assert.doesNotThrow(wrapper);
});
});
}).call(this);