Browse Source

BI-61182 test: 单测

master
windy 5 years ago
parent
commit
9e593bb5b6
  1. 5
      karma.conf.js
  2. 49
      src/core/__test__/base.test.js
  3. 2
      src/core/base.js

5
karma.conf.js

@ -57,6 +57,11 @@ module.exports = function (config) {
"test/**/*.js"
],
exclude: [
"src/base/tree/ztree/jquery.ztree.core-3.5.js",
"src/base/tree/ztree/jquery.ztree.excheck-3.5.js"
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor

49
src/core/__test__/base.test.js

@ -254,10 +254,57 @@ describe("baseFunctionTest", function () {
/**
* test_author_windy
*/
it("abc", function () {
it("others", function () {
expect(BI.abc2Int("B")).to.equal(2);
expect(BI.int2Abc(2)).to.equal("B");
expect(BI.has({a: "1", b: "2"}, "a")).to.equal(true);
expect(Object.isFrozen(BI.freeze({a: "1", b: "2"}))).to.equal(true);
expect(BI.isCapitalEqual("A", "a")).to.equal(true);
expect(BI.isEmptyString("a")).to.equal(false);
expect(BI.isNotEmptyString("a")).to.equal(true);
expect(BI.isWindow("a")).to.equal(false);
});
/**
* test_author_windy
*/
it("deepFunc", function () {
expect(BI.isDeepMatch({b: {c: {e: 3}}, d:2}, {b: {c: {e: 3}}, d:2})).to.equal(true);
expect(BI.deepIndexOf([{a: 1}, {b: 2}, {c: 3}], {c: 3})).to.equal(2);
var remove = [{a: 1}, {b: 2}, {c: 3}];
BI.deepRemove(remove, {c: 3});
expect(remove).to.deep.equal([{a: 1}, {b: 2}]);
expect(BI.deepWithout([{a: 1}, {b: 2}, {c: 3}], {c: 3})).to.deep.equal([{a: 1}, {b: 2}]);
expect(BI.deepUnique([{c: 3}, {a: 1}, {b: 2}, {c: 3}, {c: 3}])).to.deep.equal([{c: 3}, {a: 1}, {b: 2}]);
expect(BI.deepDiff({a: 1, b: 2}, {a: 1, c: 2})).to.deep.equal(["b", "c"]);
});
/**
* test_author_windy
*/
it("number", function () {
expect(BI.parseSafeInt(9007199254740992)).to.equal(9007199254740991);
expect(BI.isNegativeInteger(-3)).to.equal(true);
expect(BI.isFloat(1.2)).to.equal(false);
expect(BI.isOdd(1)).to.equal(true);
expect(BI.isOdd("a")).to.equal(false);
expect(BI.isEven("a")).to.equal(false);
expect(BI.isEven(2)).to.equal(true);
expect(BI.sum([1, 2, 3, 4, 5, 6, 7])).to.equal(28);
expect(BI.average([1, 2, 3, 4, 5, 6, 7])).to.equal(4);
});
/**
* test_author_windy
*/
it("string", function () {
expect(BI.toLowerCase("AAAAA")).to.equal("aaaaa");
expect(BI.isLiteral("AAAAA")).to.equal(false);
expect(BI.stripQuotes("AAAAA")).to.equal("AAAAA");
expect(BI.camelize("background-color")).to.equal("backgroundColor");
expect(BI.escape("'\\")).to.equal("\\'\\\\");
expect(BI.leftPad("123", 5, "0")).to.equal("00123");
var cls = 'my-class', text = 'Some text';
expect(BI.format('<div class="{0}">{1}</div>', cls, text)).to.equal('<div class="my-class">Some text</div>');
});
});

2
src/core/base.js

@ -976,7 +976,7 @@ if (!_global.BI) {
* 对字符串做替换的函数
*
* var cls = 'my-class', text = 'Some text';
* var res = BI.format('<div class="{0}>{1}</div>"', cls, text);
* var res = BI.format('<div class="{0}">{1}</div>', cls, text);
* //res的值为:'<div class="my-class">Some text</div>';
*
* @static

Loading…
Cancel
Save