Update tests.

This commit is contained in:
Lars Jung 2015-06-14 15:24:05 +02:00
parent 18a62ca831
commit 787eae7a80
22 changed files with 113 additions and 161 deletions

17
test/util/assert.js Normal file
View file

@ -0,0 +1,17 @@
(function () {
'use strict';
var assert = chai.assert;
assert.lengthOfKeys = function (val, count, msg) {
var keyCount = _.keys(val).length;
assert(keyCount === count, msg ? msg : 'expected ' + val + ' to have ' + count + ' keys, but has ' + keyCount);
};
assert.isPlainObject = function (val, msg) {
assert($.isPlainObject(val), msg ? msg : 'expected ' + val + ' to be a plain Object');
};
}());

View file

@ -1,18 +0,0 @@
(function () {
'use strict';
chai.Assertion.addChainableMethod('isPlainObject', function () {
this.assert(
$.isPlainObject(this._obj),
'expected ' + this._obj + ' to be a plain Object',
'expected ' + this._obj + ' not to be a plain Object'
);
});
chai.assert.isPlainObject = function (val, msg) {
new chai.Assertion(val, msg).to.be.isPlainObject();
};
}());

View file

@ -1,20 +0,0 @@
(function () {
'use strict';
chai.Assertion.addChainableMethod('lengthOfKeys', function (count) {
var keyCount = _.keys(this._obj).length;
this.assert(
keyCount === count,
'expected ' + this._obj + ' to have ' + count + ' keys, but has ' + keyCount,
'expected ' + this._obj + ' not to have ' + count + ' keys, but has ' + keyCount
);
});
chai.assert.lengthOfKeys = function (val, count, msg) {
new chai.Assertion(val, msg).to.be.lengthOfKeys(count);
};
}());

View file

@ -11,7 +11,7 @@ function clearModulejs() {
function mockConfigModule() {
modulejs.define('config', window.util.uniqObj());
modulejs.define('config', window.uniq.obj());
}
window.util = window.util || {};

View file

@ -1,39 +0,0 @@
(function () {
'use strict';
var PREFIX = 'UNIQ-';
var SUFFIX = '-ID';
var LENGTH = 4;
var RE = new RegExp('^' + PREFIX + '\\d{' + LENGTH + '}' + SUFFIX + '$');
var counter = 0;
function uniqId() {
counter += 1;
return PREFIX + ('00000000' + counter).substr(-LENGTH) + SUFFIX;
}
function isUniqId(uid) {
return RE.test(uid);
}
function uniqObj() {
return {uniqId: uniqId()};
}
function uniqPath(suffix) {
return '/some/path/' + uniqId() + (suffix ? suffix : '');
}
window.util = window.util || {};
window.util.uniqId = uniqId;
window.util.isUniqId = isUniqId;
window.util.uniqObj = uniqObj;
window.util.uniqPath = uniqPath;
}());