mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-31 07:18:21 -04:00
Update tests.
This commit is contained in:
parent
18a62ca831
commit
787eae7a80
22 changed files with 113 additions and 161 deletions
17
test/util/assert.js
Normal file
17
test/util/assert.js
Normal 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');
|
||||
};
|
||||
|
||||
}());
|
|
@ -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();
|
||||
};
|
||||
|
||||
}());
|
|
@ -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);
|
||||
};
|
||||
|
||||
}());
|
|
@ -11,7 +11,7 @@ function clearModulejs() {
|
|||
|
||||
function mockConfigModule() {
|
||||
|
||||
modulejs.define('config', window.util.uniqObj());
|
||||
modulejs.define('config', window.uniq.obj());
|
||||
}
|
||||
|
||||
window.util = window.util || {};
|
||||
|
|
|
@ -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;
|
||||
|
||||
}());
|
Loading…
Add table
Add a link
Reference in a new issue