mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-08-31 00:40:06 +02:00
Publish tests.
This commit is contained in:
18
test/util/chai.isPlainObject.js
Normal file
18
test/util/chai.isPlainObject.js
Normal file
@@ -0,0 +1,18 @@
|
||||
(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();
|
||||
};
|
||||
|
||||
}());
|
20
test/util/chai.lengthOfKeys.js
Normal file
20
test/util/chai.lengthOfKeys.js
Normal file
@@ -0,0 +1,20 @@
|
||||
(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);
|
||||
};
|
||||
|
||||
}());
|
2
test/util/global.js
Normal file
2
test/util/global.js
Normal file
@@ -0,0 +1,2 @@
|
||||
window.util = window.util || {};
|
||||
window.util.GLOBAL = this;
|
23
test/util/pin.js
Normal file
23
test/util/pin.js
Normal file
@@ -0,0 +1,23 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var htmlClasses;
|
||||
var $pinnedElements;
|
||||
|
||||
function pinHtml() {
|
||||
|
||||
htmlClasses = $('html').attr('class');
|
||||
$pinnedElements = $('head,body').children();
|
||||
}
|
||||
|
||||
function restoreHtml() {
|
||||
|
||||
$('html').attr('class', htmlClasses);
|
||||
$('head,body').children().not($pinnedElements).remove();
|
||||
}
|
||||
|
||||
window.util = window.util || {};
|
||||
window.util.pinHtml = pinHtml;
|
||||
window.util.restoreHtml = restoreHtml;
|
||||
|
||||
}());
|
32
test/util/uniq.js
Normal file
32
test/util/uniq.js
Normal file
@@ -0,0 +1,32 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var PREFIX = 'UQ';
|
||||
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 uniqObj() {
|
||||
|
||||
return {uniqId: uniqId()};
|
||||
}
|
||||
|
||||
function isUniqId(uid) {
|
||||
|
||||
return RE.test(uid);
|
||||
}
|
||||
|
||||
window.util = window.util || {};
|
||||
window.util.uniqId = uniqId;
|
||||
window.util.uniqObj = uniqObj;
|
||||
window.util.isUniqId = isUniqId;
|
||||
|
||||
}());
|
Reference in New Issue
Block a user