diff --git a/bower.json b/bower.json
index fd0a0a5..2d0402a 100644
--- a/bower.json
+++ b/bower.json
@@ -30,11 +30,12 @@
"zepto.js": "1.*"
},
"devDependencies": {
+ "jquery": "*",
"action": "0.3.2",
"underscore-template": "0.3.0",
"underscore.string": "2.*",
"mocha.css": "0.1.0",
"mocha": "1.*",
- "chai": "1.*"
+ "expect.js": "^0.3.1"
}
}
diff --git a/test/_sandbox.html b/test/_sandbox.html
new file mode 100644
index 0000000..b472c09
--- /dev/null
+++ b/test/_sandbox.html
@@ -0,0 +1,45 @@
+
+
+
+
+Testing Sandbox - UT - Gearbox
+
+
+
+Testing Sandbox
+
+
+
+
+
+
diff --git a/test/test-action.js b/test/test-action.js
index 02088c2..6cd2c2e 100644
--- a/test/test-action.js
+++ b/test/test-action.js
@@ -64,7 +64,7 @@ describe('Action', function () {
$wrapper.remove()
})
beforeEach(function () {
- actionName = Date.now().toString(36)
+ actionName = new Date().getTime().toString(36)
randomKey = Math.random().toString(36)
})
it('gets action name from `href`', function (done) {
diff --git a/test/test-dev.html b/test/test-dev.html
index 3e885c7..f05999f 100644
--- a/test/test-dev.html
+++ b/test/test-dev.html
@@ -18,11 +18,10 @@ UT (Dev) - Gearbox
-
+
diff --git a/test/test-dist-trad-jquery.html b/test/test-dist-trad-jquery.html
new file mode 100644
index 0000000..b725e08
--- /dev/null
+++ b/test/test-dist-trad-jquery.html
@@ -0,0 +1,45 @@
+
+
+
+
+UT (Trad) (jQuery) - Gearbox
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/test-dist-trad.html b/test/test-dist-trad.html
index 59eb283..1d61e79 100644
--- a/test/test-dist-trad.html
+++ b/test/test-dist-trad.html
@@ -18,11 +18,10 @@ UT (Trad) - Gearbox
-
+
diff --git a/test/test-dom.js b/test/test-dom.js
index 22edeb3..445135e 100644
--- a/test/test-dom.js
+++ b/test/test-dom.js
@@ -2,20 +2,20 @@ describe('DOM', function () {
describe('Shortcuts', function () {
describe('_.dom.$win', function () {
it('is $collection of `window` object', function () {
- expect(_.dom.is$Element(_.dom.$win)).to.be.true
+ expect(_.dom.is$Element(_.dom.$win)).to.equal(true)
expect(_.dom.$win[0]).to.equal(window)
})
})
describe('_.dom.$root', function () {
it('is a $collection of `document.documentElement` object', function () {
- expect(_.dom.is$Element(_.dom.$root)).to.be.true
+ expect(_.dom.is$Element(_.dom.$root)).to.equal(true)
expect(_.dom.$root[0]).to.equal(document.documentElement)
expect(_.dom.$root[0].tagName.toUpperCase()).to.equal('HTML')
})
})
describe('_.dom.$body', function () {
it('is a $collection of `document.body` object', function () {
- expect(_.dom.is$Element(_.dom.$body)).to.be.true
+ expect(_.dom.is$Element(_.dom.$body)).to.equal(true)
expect(_.dom.$body[0]).to.equal(document.body)
})
})
@@ -26,26 +26,26 @@ describe('DOM', function () {
it('checks if it\'s $collection', function () {
var arg
arg = $()
- expect(_.dom.is$Element(arg)).to.be.true
+ expect(_.dom.is$Element(arg)).to.equal(true)
arg = $(window)
- expect(_.dom.is$Element(arg)).to.be.true
+ expect(_.dom.is$Element(arg)).to.equal(true)
})
it('returns `false` if bad type of param', function () {
var arg
arg = undefined
- expect(_.dom.is$Element(arg)).to.be.false
+ expect(_.dom.is$Element(arg)).to.equal(false)
arg = null
- expect(_.dom.is$Element(arg)).to.be.false
+ expect(_.dom.is$Element(arg)).to.equal(false)
arg = 0
- expect(_.dom.is$Element(arg)).to.be.false
+ expect(_.dom.is$Element(arg)).to.equal(false)
arg = true
- expect(_.dom.is$Element(arg)).to.be.false
+ expect(_.dom.is$Element(arg)).to.equal(false)
arg = {}
- expect(_.dom.is$Element(arg)).to.be.false
+ expect(_.dom.is$Element(arg)).to.equal(false)
arg = []
- expect(_.dom.is$Element(arg)).to.be.false
+ expect(_.dom.is$Element(arg)).to.equal(false)
arg = document.documentElement
- expect(_.dom.is$Element(arg)).to.be.false
+ expect(_.dom.is$Element(arg)).to.equal(false)
})
})
})
diff --git a/test/test-root.js b/test/test-root.js
index 9e4730e..a695750 100644
--- a/test/test-root.js
+++ b/test/test-root.js
@@ -1,47 +1,47 @@
describe('(Root)', function () {
describe('_.isPlainObject()', function () {
it('is an alias of $\'s same api', function () {
- expect($.isPlainObject === _.isPlainObject).to.be.true
+ expect($.isPlainObject === _.isPlainObject).to.equal(true)
})
it('does basic functionality', function () {
var arg
arg = {}
- expect(_.isPlainObject(arg)).to.be.true
+ expect(_.isPlainObject(arg)).to.equal(true)
arg = {foo: 1, bar: 2}
- expect(_.isPlainObject(arg)).to.be.true
+ expect(_.isPlainObject(arg)).to.equal(true)
arg = new Object()
- expect(_.isPlainObject(arg)).to.be.true
+ expect(_.isPlainObject(arg)).to.equal(true)
arg = /foobar/i
- expect(_.isPlainObject(arg)).to.be.false
+ expect(_.isPlainObject(arg)).to.equal(false)
arg = new Date()
- expect(_.isPlainObject(arg)).to.be.false
+ expect(_.isPlainObject(arg)).to.equal(false)
arg = new String('foobar')
- expect(_.isPlainObject(arg)).to.be.false
+ expect(_.isPlainObject(arg)).to.equal(false)
arg = window
- expect(_.isPlainObject(arg)).to.be.false
+ expect(_.isPlainObject(arg)).to.equal(false)
arg = document.documentElement
- expect(_.isPlainObject(arg)).to.be.false
+ expect(_.isPlainObject(arg)).to.equal(false)
})
it('returns `false` if input other types', function () {
var arg
arg = undefined
- expect(_.isPlainObject(arg)).to.be.false
+ expect(_.isPlainObject(arg)).to.equal(false)
arg = null
- expect(_.isPlainObject(arg)).to.be.false
+ expect(_.isPlainObject(arg)).to.equal(false)
arg = 0
- expect(_.isPlainObject(arg)).to.be.false
+ expect(_.isPlainObject(arg)).to.equal(false)
arg = 'foobar'
- expect(_.isPlainObject(arg)).to.be.false
+ expect(_.isPlainObject(arg)).to.equal(false)
arg = true
- expect(_.isPlainObject(arg)).to.be.false
+ expect(_.isPlainObject(arg)).to.equal(false)
arg = []
- expect(_.isPlainObject(arg)).to.be.false
+ expect(_.isPlainObject(arg)).to.equal(false)
arg = it
- expect(_.isPlainObject(arg)).to.be.false
+ expect(_.isPlainObject(arg)).to.equal(false)
arg = String
- expect(_.isPlainObject(arg)).to.be.false
+ expect(_.isPlainObject(arg)).to.equal(false)
arg = Date
- expect(_.isPlainObject(arg)).to.be.false
+ expect(_.isPlainObject(arg)).to.equal(false)
})
})
@@ -49,7 +49,7 @@ describe('(Root)', function () {
it('does basic functionality same as $()', function () {
var elem = document.getElementById('mocha')
var obj = _.$(elem)
- expect(obj).to.deep.equal($(elem))
+ expect(obj).to.eql($(elem))
})
it('returns directly if already $collection', function () {
var obj = $('#mocha')
diff --git a/test/test-str-alt.js b/test/test-str-alt.js
index ac3b81a..5694118 100644
--- a/test/test-str-alt.js
+++ b/test/test-str-alt.js
@@ -45,7 +45,7 @@ describe('String - Alternative to Underscore.string', function () {
expect(_.str.ltrim('ffooff', 'f'), 'ooff')
expect(_.str.ltrim('_-foobar-_', '_-'), 'foobar-_')
-
+
expect(_.str.ltrim(123, 1), '23')
})
it('doesn\'t remove inner spaces', function () {
@@ -78,96 +78,96 @@ describe('String - Alternative to Underscore.string', function () {
describe('_.str.contains()', function () {
it('does basic functionality', function () {
- expect(_.str.contains('foobar', 'bar')).to.be.true
- expect(!_.str.contains('foobar', 'buzz')).to.be.true
- expect(_.str.contains(12345, 34)).to.be.true
- expect(!_.str.contains(12345, 6)).to.be.true
- expect(!_.str.contains('', 34)).to.be.true
- expect(!_.str.contains(null, 34)).to.be.true
- expect(_.str.contains(null, '')).to.be.true
+ expect(_.str.contains('foobar', 'bar')).to.equal(true)
+ expect(!_.str.contains('foobar', 'buzz')).to.equal(true)
+ expect(_.str.contains(12345, 34)).to.equal(true)
+ expect(!_.str.contains(12345, 6)).to.equal(true)
+ expect(!_.str.contains('', 34)).to.equal(true)
+ expect(!_.str.contains(null, 34)).to.equal(true)
+ expect(_.str.contains(null, '')).to.equal(true)
})
it('supports additional param - position', function () {
- expect(_.str.contains('foobar', 'bar', 1)).to.be.true
- expect(_.str.contains('foobar', 'bar', 2)).to.be.true
- expect(_.str.contains('foobar', 'bar', 3)).to.be.true
- expect(_.str.contains('foobar', 'bar', 4)).to.be.false
+ expect(_.str.contains('foobar', 'bar', 1)).to.equal(true)
+ expect(_.str.contains('foobar', 'bar', 2)).to.equal(true)
+ expect(_.str.contains('foobar', 'bar', 3)).to.equal(true)
+ expect(_.str.contains('foobar', 'bar', 4)).to.equal(false)
})
})
describe('_.str.startsWith()', function () {
it('does basic functionality', function () {
- expect(_.str.startsWith('foobar', 'foo')).to.be.true
- expect(!_.str.startsWith('oobar', 'foo')).to.be.true
- expect(_.str.startsWith('oobar', 'o')).to.be.true
- expect(_.str.startsWith(12345, 123)).to.be.true
- expect(!_.str.startsWith(2345, 123)).to.be.true
- expect(_.str.startsWith('', '')).to.be.true
- expect(_.str.startsWith(null, '')).to.be.true
- expect(!_.str.startsWith(null, 'foo')).to.be.true
-
- expect(_.str.startsWith('-foobar', 'foo', 1)).to.be.true
- expect(_.str.startsWith('foobar', 'foo', 0)).to.be.true
- expect(!_.str.startsWith('foobar', 'foo', 1)).to.be.true
-
- expect(_.str.startsWith('Äpfel', 'Ä')).to.be.true
-
- expect(_.str.startsWith('hello', 'hell')).to.be.true
- expect(_.str.startsWith('HELLO', 'HELL')).to.be.true
- expect(_.str.startsWith('HELLO', 'hell')).to.be.false
- expect(_.str.startsWith('HELLO', 'hell')).to.be.false
- expect(_.str.startsWith('hello', 'hell', 0)).to.be.true
- expect(_.str.startsWith('HELLO', 'HELL', 0)).to.be.true
- expect(_.str.startsWith('HELLO', 'hell', 0)).to.be.false
- expect(_.str.startsWith('HELLO', 'hell', 0)).to.be.false
- expect(_.str.startsWith('HELLO')).to.be.false
- expect(_.str.startsWith('undefined')).to.be.true
- expect(_.str.startsWith('null', null)).to.be.true
- expect(_.str.startsWith('hello', 'hell', -20)).to.be.true
- expect(_.str.startsWith('hello', 'hell', 1)).to.be.false
- expect(_.str.startsWith('hello', 'hell', 2)).to.be.false
- expect(_.str.startsWith('hello', 'hell', 3)).to.be.false
- expect(_.str.startsWith('hello', 'hell', 4)).to.be.false
- expect(_.str.startsWith('hello', 'hell', 5)).to.be.false
- expect(_.str.startsWith('hello', 'hell', 20)).to.be.false
+ expect(_.str.startsWith('foobar', 'foo')).to.equal(true)
+ expect(!_.str.startsWith('oobar', 'foo')).to.equal(true)
+ expect(_.str.startsWith('oobar', 'o')).to.equal(true)
+ expect(_.str.startsWith(12345, 123)).to.equal(true)
+ expect(!_.str.startsWith(2345, 123)).to.equal(true)
+ expect(_.str.startsWith('', '')).to.equal(true)
+ expect(_.str.startsWith(null, '')).to.equal(true)
+ expect(!_.str.startsWith(null, 'foo')).to.equal(true)
+
+ expect(_.str.startsWith('-foobar', 'foo', 1)).to.equal(true)
+ expect(_.str.startsWith('foobar', 'foo', 0)).to.equal(true)
+ expect(!_.str.startsWith('foobar', 'foo', 1)).to.equal(true)
+
+ expect(_.str.startsWith('Äpfel', 'Ä')).to.equal(true)
+
+ expect(_.str.startsWith('hello', 'hell')).to.equal(true)
+ expect(_.str.startsWith('HELLO', 'HELL')).to.equal(true)
+ expect(_.str.startsWith('HELLO', 'hell')).to.equal(false)
+ expect(_.str.startsWith('HELLO', 'hell')).to.equal(false)
+ expect(_.str.startsWith('hello', 'hell', 0)).to.equal(true)
+ expect(_.str.startsWith('HELLO', 'HELL', 0)).to.equal(true)
+ expect(_.str.startsWith('HELLO', 'hell', 0)).to.equal(false)
+ expect(_.str.startsWith('HELLO', 'hell', 0)).to.equal(false)
+ expect(_.str.startsWith('HELLO')).to.equal(false)
+ expect(_.str.startsWith('undefined')).to.equal(true)
+ expect(_.str.startsWith('null', null)).to.equal(true)
+ expect(_.str.startsWith('hello', 'hell', -20)).to.equal(true)
+ expect(_.str.startsWith('hello', 'hell', 1)).to.equal(false)
+ expect(_.str.startsWith('hello', 'hell', 2)).to.equal(false)
+ expect(_.str.startsWith('hello', 'hell', 3)).to.equal(false)
+ expect(_.str.startsWith('hello', 'hell', 4)).to.equal(false)
+ expect(_.str.startsWith('hello', 'hell', 5)).to.equal(false)
+ expect(_.str.startsWith('hello', 'hell', 20)).to.equal(false)
});
})
describe('_.str.endsWith()', function () {
it('does basic functionality', function () {
- expect(_.str.endsWith('foobar', 'bar')).to.be.true
- expect(_.str.endsWith('foobarfoobar', 'bar')).to.be.true
- expect(_.str.endsWith('foo', 'o')).to.be.true
- expect(_.str.endsWith('foobar', 'bar')).to.be.true
- expect(_.str.endsWith('00018-0000062.Plone.sdh264.1a7264e6912a91aa4a81b64dc5517df7b8875994.mp4', 'mp4')).to.be.true
- expect(!_.str.endsWith('fooba', 'bar')).to.be.true
- expect(_.str.endsWith(12345, 45)).to.be.true
- expect(!_.str.endsWith(12345, 6)).to.be.true
- expect(_.str.endsWith('', '')).to.be.true
- expect(_.str.endsWith(null, '')).to.be.true
- expect(!_.str.endsWith(null, 'foo')).to.be.true
-
- expect(_.str.endsWith('foobar?', 'bar', 6)).to.be.true
- expect(_.str.endsWith(12345, 34, 4)).to.be.true
- expect(!_.str.endsWith(12345, 45, 4)).to.be.true
-
- expect(_.str.endsWith('foobä', 'ä')).to.be.true
-
- expect(_.str.endsWith('vader', 'der')).to.be.true
- expect(_.str.endsWith('VADER', 'DER')).to.be.true
- expect(_.str.endsWith('VADER', 'der')).to.be.false
- expect(_.str.endsWith('VADER', 'DeR')).to.be.false
- expect(_.str.endsWith('VADER')).to.be.false
- expect(_.str.endsWith('undefined')).to.be.true
- expect(_.str.endsWith('null', null)).to.be.true
- expect(_.str.endsWith('vader', 'der', 5)).to.be.true
- expect(_.str.endsWith('VADER', 'DER', 5)).to.be.true
- expect(_.str.endsWith('VADER', 'der', 5)).to.be.false
- expect(_.str.endsWith('VADER', 'DER', 5)).to.be.true
- expect(_.str.endsWith('VADER', 'der', 5)).to.be.false
- expect(_.str.endsWith('vader', 'der', -20)).to.be.false
- expect(_.str.endsWith('vader', 'der', 0)).to.be.false
- expect(_.str.endsWith('vader', 'der', 1)).to.be.false
- expect(_.str.endsWith('vader', 'der', 2)).to.be.false
- expect(_.str.endsWith('vader', 'der', 3)).to.be.false
- expect(_.str.endsWith('vader', 'der', 4)).to.be.false
+ expect(_.str.endsWith('foobar', 'bar')).to.equal(true)
+ expect(_.str.endsWith('foobarfoobar', 'bar')).to.equal(true)
+ expect(_.str.endsWith('foo', 'o')).to.equal(true)
+ expect(_.str.endsWith('foobar', 'bar')).to.equal(true)
+ expect(_.str.endsWith('00018-0000062.Plone.sdh264.1a7264e6912a91aa4a81b64dc5517df7b8875994.mp4', 'mp4')).to.equal(true)
+ expect(!_.str.endsWith('fooba', 'bar')).to.equal(true)
+ expect(_.str.endsWith(12345, 45)).to.equal(true)
+ expect(!_.str.endsWith(12345, 6)).to.equal(true)
+ expect(_.str.endsWith('', '')).to.equal(true)
+ expect(_.str.endsWith(null, '')).to.equal(true)
+ expect(!_.str.endsWith(null, 'foo')).to.equal(true)
+
+ expect(_.str.endsWith('foobar?', 'bar', 6)).to.equal(true)
+ expect(_.str.endsWith(12345, 34, 4)).to.equal(true)
+ expect(!_.str.endsWith(12345, 45, 4)).to.equal(true)
+
+ expect(_.str.endsWith('foobä', 'ä')).to.equal(true)
+
+ expect(_.str.endsWith('vader', 'der')).to.equal(true)
+ expect(_.str.endsWith('VADER', 'DER')).to.equal(true)
+ expect(_.str.endsWith('VADER', 'der')).to.equal(false)
+ expect(_.str.endsWith('VADER', 'DeR')).to.equal(false)
+ expect(_.str.endsWith('VADER')).to.equal(false)
+ expect(_.str.endsWith('undefined')).to.equal(true)
+ expect(_.str.endsWith('null', null)).to.equal(true)
+ expect(_.str.endsWith('vader', 'der', 5)).to.equal(true)
+ expect(_.str.endsWith('VADER', 'DER', 5)).to.equal(true)
+ expect(_.str.endsWith('VADER', 'der', 5)).to.equal(false)
+ expect(_.str.endsWith('VADER', 'DER', 5)).to.equal(true)
+ expect(_.str.endsWith('VADER', 'der', 5)).to.equal(false)
+ expect(_.str.endsWith('vader', 'der', -20)).to.equal(false)
+ expect(_.str.endsWith('vader', 'der', 0)).to.equal(false)
+ expect(_.str.endsWith('vader', 'der', 1)).to.equal(false)
+ expect(_.str.endsWith('vader', 'der', 2)).to.equal(false)
+ expect(_.str.endsWith('vader', 'der', 3)).to.equal(false)
+ expect(_.str.endsWith('vader', 'der', 4)).to.equal(false)
});
})
diff --git a/test/test-str.js b/test/test-str.js
index 79eb4c7..e855acf 100644
--- a/test/test-str.js
+++ b/test/test-str.js
@@ -7,90 +7,90 @@ describe('String', function () {
var arg
// normal email addr
arg = 'dev' + CHAR_AT + 'cmui.net'
- expect(_.str.RE_EMAIL.test(arg)).to.be.true
+ expect(_.str.RE_EMAIL.test(arg)).to.equal(true)
// domain can be any level
arg = 'dev' + CHAR_AT + 'gearbox.by.cmui.net'
- expect(_.str.RE_EMAIL.test(arg)).to.be.true
+ expect(_.str.RE_EMAIL.test(arg)).to.equal(true)
// future proof for unknown domain suffix
arg = 'dev' + CHAR_AT + 'gearbox.rocks'
- expect(_.str.RE_EMAIL.test(arg)).to.be.true
+ expect(_.str.RE_EMAIL.test(arg)).to.equal(true)
// username can be numbers
arg = '007' + CHAR_AT + 'cmui.net'
- expect(_.str.RE_EMAIL.test(arg)).to.be.true
+ expect(_.str.RE_EMAIL.test(arg)).to.equal(true)
// domain name can be numbers
arg = 'username' + CHAR_AT + '126.com'
- expect(_.str.RE_EMAIL.test(arg)).to.be.true
+ expect(_.str.RE_EMAIL.test(arg)).to.equal(true)
// email can be in upper case
arg = 'DEV' + CHAR_AT + 'CMUI.NET'
- expect(_.str.RE_EMAIL.test(arg)).to.be.true
+ expect(_.str.RE_EMAIL.test(arg)).to.equal(true)
})
it('recognizes bad value', function () {
var arg
// domain suffix need at least 2 letters
arg = 'a' + CHAR_AT + 'a.a'
- expect(_.str.RE_EMAIL.test(arg)).to.be.false
+ expect(_.str.RE_EMAIL.test(arg)).to.equal(false)
// domain suffix cannot be numbers
arg = '007' + CHAR_AT + '007.007'
- expect(_.str.RE_EMAIL.test(arg)).to.be.false
+ expect(_.str.RE_EMAIL.test(arg)).to.equal(false)
// domain cannot be ip addr
arg = 'a' + CHAR_AT + '192.168.10.10'
- expect(_.str.RE_EMAIL.test(arg)).to.be.false
+ expect(_.str.RE_EMAIL.test(arg)).to.equal(false)
})
})
describe('_.str.RE_MOBILE', function () {
it('matches mobile number', function () {
var arg
arg = '13000000000'
- expect(_.str.RE_MOBILE.test(arg)).to.be.true
+ expect(_.str.RE_MOBILE.test(arg)).to.equal(true)
arg = '13322558899'
- expect(_.str.RE_MOBILE.test(arg)).to.be.true
+ expect(_.str.RE_MOBILE.test(arg)).to.equal(true)
arg = '15966558877'
- expect(_.str.RE_MOBILE.test(arg)).to.be.true
+ expect(_.str.RE_MOBILE.test(arg)).to.equal(true)
arg = '18055668899'
- expect(_.str.RE_MOBILE.test(arg)).to.be.true
+ expect(_.str.RE_MOBILE.test(arg)).to.equal(true)
arg = 18978963214
- expect(_.str.RE_MOBILE.test(arg)).to.be.true
+ expect(_.str.RE_MOBILE.test(arg)).to.equal(true)
})
it('recognizes bad value', function () {
var arg
arg = '12000000000'
- expect(_.str.RE_MOBILE.test(arg)).to.be.false
+ expect(_.str.RE_MOBILE.test(arg)).to.equal(false)
arg = '1332255889'
- expect(_.str.RE_MOBILE.test(arg)).to.be.false
+ expect(_.str.RE_MOBILE.test(arg)).to.equal(false)
arg = '133-2255-8899'
- expect(_.str.RE_MOBILE.test(arg)).to.be.false
+ expect(_.str.RE_MOBILE.test(arg)).to.equal(false)
arg = 'foobar'
- expect(_.str.RE_MOBILE.test(arg)).to.be.false
+ expect(_.str.RE_MOBILE.test(arg)).to.equal(false)
})
})
describe('_.str.RE_POSTCODE', function () {
it('matches postcode', function () {
var arg
arg = '000000'
- expect(_.str.RE_POSTCODE.test(arg)).to.be.true
+ expect(_.str.RE_POSTCODE.test(arg)).to.equal(true)
arg = '001100'
- expect(_.str.RE_POSTCODE.test(arg)).to.be.true
+ expect(_.str.RE_POSTCODE.test(arg)).to.equal(true)
arg = '220000'
- expect(_.str.RE_POSTCODE.test(arg)).to.be.true
+ expect(_.str.RE_POSTCODE.test(arg)).to.equal(true)
arg = '000022'
- expect(_.str.RE_POSTCODE.test(arg)).to.be.true
+ expect(_.str.RE_POSTCODE.test(arg)).to.equal(true)
arg = '336699'
- expect(_.str.RE_POSTCODE.test(arg)).to.be.true
+ expect(_.str.RE_POSTCODE.test(arg)).to.equal(true)
arg = 114477
- expect(_.str.RE_POSTCODE.test(arg)).to.be.true
+ expect(_.str.RE_POSTCODE.test(arg)).to.equal(true)
})
it('recognizes bad value', function () {
var arg
arg = '11111'
- expect(_.str.RE_POSTCODE.test(arg)).to.be.false
+ expect(_.str.RE_POSTCODE.test(arg)).to.equal(false)
arg = '5555555'
- expect(_.str.RE_POSTCODE.test(arg)).to.be.false
+ expect(_.str.RE_POSTCODE.test(arg)).to.equal(false)
arg = '22-55-66'
- expect(_.str.RE_POSTCODE.test(arg)).to.be.false
+ expect(_.str.RE_POSTCODE.test(arg)).to.equal(false)
arg = 077777
- expect(_.str.RE_POSTCODE.test(arg)).to.be.false
+ expect(_.str.RE_POSTCODE.test(arg)).to.equal(false)
arg = 'foobar'
- expect(_.str.RE_POSTCODE.test(arg)).to.be.false
+ expect(_.str.RE_POSTCODE.test(arg)).to.equal(false)
})
})
})
@@ -116,41 +116,41 @@ describe('String', function () {
it('returns `true` if a string starts with `#`', function () {
var arg
arg = 'foo'
- expect(_.str.isHash(arg)).to.be.false
+ expect(_.str.isHash(arg)).to.equal(false)
arg = '#foo'
- expect(_.str.isHash(arg)).to.be.true
+ expect(_.str.isHash(arg)).to.equal(true)
arg = '###bar'
- expect(_.str.isHash(arg)).to.be.true
+ expect(_.str.isHash(arg)).to.equal(true)
arg = '#!foobar'
- expect(_.str.isHash(arg)).to.be.true
+ expect(_.str.isHash(arg)).to.equal(true)
})
it('ignores initial spaces', function () {
var arg
arg = ' foo '
- expect(_.str.isHash(arg)).to.be.false
+ expect(_.str.isHash(arg)).to.equal(false)
arg = ' #foo '
- expect(_.str.isHash(arg)).to.be.true
+ expect(_.str.isHash(arg)).to.equal(true)
arg = ' ###bar '
- expect(_.str.isHash(arg)).to.be.true
+ expect(_.str.isHash(arg)).to.equal(true)
arg = ' #!foobar '
- expect(_.str.isHash(arg)).to.be.true
+ expect(_.str.isHash(arg)).to.equal(true)
})
it('returns `false` if bad type of param', function () {
var arg
arg = undefined
- expect(_.str.isHash(arg)).to.be.false
+ expect(_.str.isHash(arg)).to.equal(false)
arg = null
- expect(_.str.isHash(arg)).to.be.false
+ expect(_.str.isHash(arg)).to.equal(false)
arg = 0
- expect(_.str.isHash(arg)).to.be.false
+ expect(_.str.isHash(arg)).to.equal(false)
arg = true
- expect(_.str.isHash(arg)).to.be.false
+ expect(_.str.isHash(arg)).to.equal(false)
arg = {}
- expect(_.str.isHash(arg)).to.be.false
+ expect(_.str.isHash(arg)).to.equal(false)
arg = []
- expect(_.str.isHash(arg)).to.be.false
+ expect(_.str.isHash(arg)).to.equal(false)
arg = function () {}
- expect(_.str.isHash(arg)).to.be.false
+ expect(_.str.isHash(arg)).to.equal(false)
})
})
describe('_.str.stripHash()', function () {
@@ -207,7 +207,7 @@ describe('String', function () {
expect(_.str.toFloat('-2e3')).to.equal(-2000)
expect(_.str.toFloat('1.23foo')).to.equal(1.23)
expect(_.str.toFloat('-1.23foo')).to.equal(-1.23)
- expect(isNaN(_.str.toFloat('foo123'))).to.be.true
+ expect(isNaN(_.str.toFloat('foo123'))).to.equal(true)
})
})
describe('_.str.toInt()', function () {
@@ -223,7 +223,7 @@ describe('String', function () {
expect(_.str.toInt('-2e100')).to.equal(-2e100)
expect(_.str.toInt('1.23foo')).to.equal(1)
expect(_.str.toInt('-1.23foo')).to.equal(-1)
- expect(isNaN(_.str.toInt('foo123'))).to.be.true
+ expect(isNaN(_.str.toInt('foo123'))).to.equal(true)
})
})
describe('_.str.toFixed()', function () {
@@ -239,7 +239,7 @@ describe('String', function () {
expect(_.str.toFixed('-2e3', 3)).to.equal(-2000)
expect(_.str.toFixed('1.23foo', 1)).to.equal(1.2)
expect(_.str.toFixed('-1.23foo', 1)).to.equal(-1.2)
- expect(isNaN(_.str.toFixed('foo123'))).to.be.true
+ expect(isNaN(_.str.toFixed('foo123'))).to.equal(true)
})
})
})
diff --git a/test/test-template.js b/test/test-template.js
index 4f43716..b793704 100644
--- a/test/test-template.js
+++ b/test/test-template.js
@@ -56,36 +56,38 @@ describe('Template', function () {
})
})
describe('_.template.render()', function () {
- // dummy script elements
- var $elem1
- var $elem2
- function prepareDummyScript() {
- $elem1 = $('', {
- type: SCRIPT_TYPE,
- id: PREFIX + TEMPLATE_ELEM_ID_1
- }).text(templateCode1).appendTo(_.dom.$body)
- $elem2 = $('', {
- type: SCRIPT_TYPE,
- id: PREFIX + TEMPLATE_ELEM_ID_2
- }).text(templateCode2).appendTo(_.dom.$body)
+ function _prepareDummyScript() {
+ var body = document.body
+ var script1 = document.createElement('script')
+ script1.type = SCRIPT_TYPE
+ script1.id = PREFIX + TEMPLATE_ELEM_ID_1
+ script1.text = templateCode1
+ body.appendChild(script1)
+
+ var script2 = document.createElement('script')
+ script2.type = SCRIPT_TYPE
+ script2.id = PREFIX + TEMPLATE_ELEM_ID_2
+ script2.text = templateCode2
+ body.appendChild(script2)
+ }
+ function _destroyDummyScript() {
+ $("#" + PREFIX + TEMPLATE_ELEM_ID_1).remove()
+ $("#" + PREFIX + TEMPLATE_ELEM_ID_2).remove()
}
- function destroyDummyScript() {
- $elem1.remove()
- $elem2.remove()
+ function _cleanStr(str) {
+ str = String(str)
+ return str.replace(/\s+/g, ' ')
}
it('gets template from dom, then renders it', function () {
- prepareDummyScript()
+ _prepareDummyScript()
html1 = _.template.render(TEMPLATE_ELEM_ID_1, templateData1)
expect(html1).to.equal(result1)
html2 = _.template.render(TEMPLATE_ELEM_ID_2, templateData2)
- // todo: need `_.str.clean()`
- html2 = html2.replace(/\s+/g, ' ')
- result2 = result2.replace(/\s+/g, ' ')
- expect(html2).to.equal(result2)
+ expect(_cleanStr(html2)).to.equal(_cleanStr(result2))
- destroyDummyScript()
+ _destroyDummyScript()
})
it('adds template manually, then renders it', function () {
// use `add()` api to
@@ -95,10 +97,7 @@ describe('Template', function () {
html1 = _.template.render(TEMPLATE_CODE_ID_1, templateData1)
expect(html1).to.equal(result1)
html2 = _.template.render(TEMPLATE_CODE_ID_2, templateData2)
- // todo: need `_.str.clean()`
- html2 = html2.replace(/\s+/g, ' ')
- result2 = result2.replace(/\s+/g, ' ')
- expect(html2).to.equal(result2)
+ expect(_cleanStr(html2)).to.equal(_cleanStr(result2))
})
it('gets template from cache, then renders it', function () {
// notice: after above testing, there have been 4 templates in cache
@@ -106,18 +105,12 @@ describe('Template', function () {
html1 = _.template.render(TEMPLATE_ELEM_ID_1, templateData1)
expect(html1).to.equal(result1)
html2 = _.template.render(TEMPLATE_ELEM_ID_2, templateData2)
- // todo: need `_.str.clean()`
- html2 = html2.replace(/\s+/g, ' ')
- result2 = result2.replace(/\s+/g, ' ')
- expect(html2).to.equal(result2)
+ expect(_cleanStr(html2)).to.equal(_cleanStr(result2))
html1 = _.template.render(TEMPLATE_CODE_ID_1, templateData1)
expect(html1).to.equal(result1)
html2 = _.template.render(TEMPLATE_CODE_ID_2, templateData2)
- // todo: need `_.str.clean()`
- html2 = html2.replace(/\s+/g, ' ')
- result2 = result2.replace(/\s+/g, ' ')
- expect(html2).to.equal(result2)
+ expect(_cleanStr(html2)).to.equal(_cleanStr(result2))
})
})
diff --git a/test/test-ua.js b/test/test-ua.js
index 214223e..5083247 100644
--- a/test/test-ua.js
+++ b/test/test-ua.js
@@ -47,10 +47,10 @@ describe('UA', function () {
it('means element has `touch-` event', function () {
// this test case is based on the idea of feature detection.
if (_.ua.isTouchDevice) {
- expect('TouchEvent' in window).to.be.true
- expect('ontouchstart' in window).to.be.true
- expect('ontouchmove' in window).to.be.true
- expect('ontouchend' in window).to.be.true
+ expect('TouchEvent' in window).to.equal(true)
+ expect('ontouchstart' in window).to.equal(true)
+ expect('ontouchmove' in window).to.equal(true)
+ expect('ontouchend' in window).to.equal(true)
}
})
})
@@ -80,12 +80,12 @@ describe('UA', function () {
describe('iOS Safari', function () {
it('recognizes iphone_ios_40', function () {
var ua = _detect(iphone_ios_40)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.true
- expect(!!ua.isAndroid).to.be.false
- expect(!!ua.isIPhone).to.be.true
- expect(!!ua.isIPod).to.be.false
- expect(!!ua.isIPad).to.be.false
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(true)
+ expect(!!ua.isAndroid).to.equal(false)
+ expect(!!ua.isIPhone).to.equal(true)
+ expect(!!ua.isIPod).to.equal(false)
+ expect(!!ua.isIPad).to.equal(false)
expect(ua.osVersion).to.equal('4.0')
//expect(ua.browser).to.equal('safari')
expect(ua.engine).to.equal('webkit')
@@ -93,12 +93,12 @@ describe('UA', function () {
})
it('recognizes ipod_ios_30', function () {
var ua = _detect(ipod_ios_30)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.true
- expect(!!ua.isAndroid).to.be.false
- expect(!!ua.isIPhone).to.be.false
- expect(!!ua.isIPod).to.be.true
- expect(!!ua.isIPad).to.be.false
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(true)
+ expect(!!ua.isAndroid).to.equal(false)
+ expect(!!ua.isIPhone).to.equal(false)
+ expect(!!ua.isIPod).to.equal(true)
+ expect(!!ua.isIPad).to.equal(false)
expect(ua.osVersion).to.equal('3.0')
//expect(ua.browser).to.equal('safari')
expect(ua.engine).to.equal('webkit')
@@ -106,12 +106,12 @@ describe('UA', function () {
})
it('recognizes ipad_ios_322', function () {
var ua = _detect(ipad_ios_322)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.true
- expect(!!ua.isAndroid).to.be.false
- expect(!!ua.isIPhone).to.be.false
- expect(!!ua.isIPod).to.be.false
- expect(!!ua.isIPad).to.be.true
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(true)
+ expect(!!ua.isAndroid).to.equal(false)
+ expect(!!ua.isIPhone).to.equal(false)
+ expect(!!ua.isIPod).to.equal(false)
+ expect(!!ua.isIPad).to.equal(true)
expect(ua.osVersion).to.equal('3.2')
//expect(ua.browser).to.equal('safari')
expect(ua.engine).to.equal('webkit')
@@ -119,12 +119,12 @@ describe('UA', function () {
})
it('recognizes iphone_ios_60', function () {
var ua = _detect(iphone_ios_60)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.true
- expect(!!ua.isAndroid).to.be.false
- expect(!!ua.isIPhone).to.be.true
- expect(!!ua.isIPod).to.be.false
- expect(!!ua.isIPad).to.be.false
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(true)
+ expect(!!ua.isAndroid).to.equal(false)
+ expect(!!ua.isIPhone).to.equal(true)
+ expect(!!ua.isIPod).to.equal(false)
+ expect(!!ua.isIPad).to.equal(false)
expect(ua.osVersion).to.equal('6.0')
//expect(ua.browser).to.equal('safari')
expect(ua.engine).to.equal('webkit')
@@ -146,9 +146,9 @@ describe('UA', function () {
describe('iOS Third-Party Browser', function () {
it('recognizes uc_ios_421', function () {
var ua = _detect(uc_ios_421)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.true
- expect(!!ua.isAndroid).to.be.false
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(true)
+ expect(!!ua.isAndroid).to.equal(false)
expect(ua.osVersion).to.equal('4.2')
expect(ua.browser).to.equal('uc')
expect(ua.engine).to.equal('webkit')
@@ -156,9 +156,9 @@ describe('UA', function () {
})
it('recognizes uc_ios_501', function () {
var ua = _detect(uc_ios_501)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.true
- expect(!!ua.isAndroid).to.be.false
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(true)
+ expect(!!ua.isAndroid).to.equal(false)
expect(ua.osVersion).to.equal('5.0')
expect(ua.browser).to.equal('uc')
expect(ua.engine).to.equal('webkit')
@@ -166,12 +166,12 @@ describe('UA', function () {
})
it('recognizes qq_ios_511', function () {
var ua = _detect(qq_ios_511)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.true
- expect(!!ua.isAndroid).to.be.false
- expect(!!ua.isIPhone).to.be.true
- expect(!!ua.isIPod).to.be.false
- expect(!!ua.isIPad).to.be.false
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(true)
+ expect(!!ua.isAndroid).to.equal(false)
+ expect(!!ua.isIPhone).to.equal(true)
+ expect(!!ua.isIPod).to.equal(false)
+ expect(!!ua.isIPad).to.equal(false)
expect(ua.osVersion).to.equal('5.1')
expect(ua.browser).to.equal('m-qq-browser')
expect(ua.engine).to.equal('webkit')
@@ -179,13 +179,13 @@ describe('UA', function () {
})
it('recognizes gc_ios_511', function () {
var ua = _detect(gc_ios_511)
- expect(!!ua.isChrome).to.be.true
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.true
- expect(!!ua.isAndroid).to.be.false
- expect(!!ua.isIPhone).to.be.true
- expect(!!ua.isIPod).to.be.false
- expect(!!ua.isIPad).to.be.false
+ expect(!!ua.isChrome).to.equal(true)
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(true)
+ expect(!!ua.isAndroid).to.equal(false)
+ expect(!!ua.isIPhone).to.equal(true)
+ expect(!!ua.isIPod).to.equal(false)
+ expect(!!ua.isIPad).to.equal(false)
expect(ua.osVersion).to.equal('7.0')
expect(ua.browser).to.equal('chrome')
expect(ua.engine).to.equal('webkit')
@@ -218,9 +218,9 @@ describe('UA', function () {
describe('Android Browser', function () {
it('recognizes adr_21', function () {
var ua = _detect(adr_21)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.false
- expect(!!ua.isAndroid).to.be.true
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(false)
+ expect(!!ua.isAndroid).to.equal(true)
expect(ua.osVersion).to.equal('2.1')
expect(ua.browser).to.equal('')
expect(ua.engine).to.equal('webkit')
@@ -228,9 +228,9 @@ describe('UA', function () {
})
it('recognizes adr_22', function () {
var ua = _detect(adr_22)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.false
- expect(!!ua.isAndroid).to.be.true
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(false)
+ expect(!!ua.isAndroid).to.equal(true)
expect(ua.osVersion).to.equal('2.2')
expect(ua.browser).to.equal('')
expect(ua.engine).to.equal('webkit')
@@ -238,9 +238,9 @@ describe('UA', function () {
})
it('recognizes adr_234', function () {
var ua = _detect(adr_234)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.false
- expect(!!ua.isAndroid).to.be.true
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(false)
+ expect(!!ua.isAndroid).to.equal(true)
expect(ua.osVersion).to.equal('2.3')
expect(ua.browser).to.equal('')
expect(ua.engine).to.equal('webkit')
@@ -248,9 +248,9 @@ describe('UA', function () {
})
it('recognizes adr_403', function () {
var ua = _detect(adr_403)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.false
- expect(!!ua.isAndroid).to.be.true
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(false)
+ expect(!!ua.isAndroid).to.equal(true)
expect(ua.osVersion).to.equal('4.0')
expect(ua.browser).to.equal('')
expect(ua.engine).to.equal('webkit')
@@ -259,9 +259,9 @@ describe('UA', function () {
it('recognizes gc_adr_404', function () {
var ua = _detect(gc_adr_404)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.false
- expect(!!ua.isAndroid).to.be.true
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(false)
+ expect(!!ua.isAndroid).to.equal(true)
expect(ua.osVersion).to.equal('4.0')
expect(ua.browser).to.equal('chrome')
expect(ua.engine).to.equal('chrome')
@@ -272,9 +272,9 @@ describe('UA', function () {
describe('Android Third-Party Browser', function () {
it('recognizes uc_adr_233', function () {
var ua = _detect(uc_adr_233)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.false
- expect(!!ua.isAndroid).to.be.true
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(false)
+ expect(!!ua.isAndroid).to.equal(true)
expect(ua.osVersion).to.equal('2.3')
expect(ua.browser).to.equal('uc')
expect(ua.engine).to.equal('')
@@ -282,9 +282,9 @@ describe('UA', function () {
})
it('recognizes uc_adr_234', function () {
var ua = _detect(uc_adr_234)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.false
- expect(!!ua.isAndroid).to.be.true
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(false)
+ expect(!!ua.isAndroid).to.equal(true)
expect(ua.osVersion).to.equal('2.3')
expect(ua.browser).to.equal('uc')
expect(ua.engine).to.equal('')
@@ -292,9 +292,9 @@ describe('UA', function () {
})
it('recognizes uc_adr_404', function () {
var ua = _detect(uc_adr_404)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.false
- expect(!!ua.isAndroid).to.be.true
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(false)
+ expect(!!ua.isAndroid).to.equal(true)
expect(ua.osVersion).to.equal('4.0')
expect(ua.browser).to.equal('uc')
expect(ua.engine).to.equal('')
@@ -302,9 +302,9 @@ describe('UA', function () {
})
it('recognizes uc_adr_00', function () {
var ua = _detect(uc_adr_00)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.false
- expect(!!ua.isAndroid).to.be.true
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(false)
+ expect(!!ua.isAndroid).to.equal(true)
expect(ua.osVersion).to.equal('')
expect(ua.browser).to.equal('uc')
expect(ua.engine).to.equal('webkit')
@@ -313,9 +313,9 @@ describe('UA', function () {
it('recognizes qq_adr_422', function () {
var ua = _detect(qq_adr_422)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.false
- expect(!!ua.isAndroid).to.be.true
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(false)
+ expect(!!ua.isAndroid).to.equal(true)
expect(ua.osVersion).to.equal('4.2')
expect(ua.browser).to.equal('m-qq-browser')
expect(ua.engine).to.equal('webkit')
@@ -324,9 +324,9 @@ describe('UA', function () {
it('recognizes ff_adr_00', function () {
var ua = _detect(ff_adr_00)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.false
- expect(!!ua.isAndroid).to.be.true
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(false)
+ expect(!!ua.isAndroid).to.equal(true)
expect(ua.osVersion).to.equal('')
expect(ua.browser).to.equal('firefox')
expect(ua.engine).to.equal('gecko')
@@ -335,9 +335,9 @@ describe('UA', function () {
it('recognizes op_adr_404', function () {
var ua = _detect(op_adr_404)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.false
- expect(!!ua.isAndroid).to.be.true
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(false)
+ expect(!!ua.isAndroid).to.equal(true)
expect(ua.osVersion).to.equal('4.0')
expect(ua.browser).to.equal('opera')
expect(ua.engine).to.equal('presto')
@@ -346,9 +346,9 @@ describe('UA', function () {
it('recognizes xx_adr_235', function () {
var ua = _detect(xx_adr_235)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.false
- expect(!!ua.isAndroid).to.be.true
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(false)
+ expect(!!ua.isAndroid).to.equal(true)
expect(ua.osVersion).to.equal('2.3')
expect(ua.browser).to.equal('')
expect(ua.engine).to.equal('webkit')
@@ -356,9 +356,9 @@ describe('UA', function () {
})
it('recognizes xx_adr_22', function () {
var ua = _detect(xx_adr_22)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.false
- expect(!!ua.isAndroid).to.be.true
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(false)
+ expect(!!ua.isAndroid).to.equal(true)
expect(ua.osVersion).to.equal('2.2')
expect(ua.browser).to.equal('')
expect(ua.engine).to.equal('')
@@ -371,9 +371,9 @@ describe('UA', function () {
describe('Android Chrome WebView', function () {
it('recognizes wv_adr_511', function () {
var ua = _detect(wv_adr_511)
- expect(ua.isMobileDevice).to.be.true
- expect(!!ua.isIOS).to.be.false
- expect(!!ua.isAndroid).to.be.true
+ expect(ua.isMobileDevice).to.equal(true)
+ expect(!!ua.isIOS).to.equal(false)
+ expect(!!ua.isAndroid).to.equal(true)
expect(ua.osVersion).to.equal('5.1')
expect(ua.browser).to.equal('chrome-webview')
expect(ua.engine).to.equal('chrome')
@@ -389,9 +389,9 @@ describe('UA', function () {
describe('Other UA', function () {
it('recognizes ff_mac', function () {
var ua = _detect(ff_mac)
- expect(ua.isMobileDevice).to.be.false
- expect(!!ua.isIOS).to.be.false
- expect(!!ua.isAndroid).to.be.false
+ expect(ua.isMobileDevice).to.equal(false)
+ expect(!!ua.isIOS).to.equal(false)
+ expect(!!ua.isAndroid).to.equal(false)
expect(ua.osVersion).to.equal('')
expect(ua.browser).to.equal('firefox')
expect(ua.engine).to.equal('gecko')
@@ -399,9 +399,9 @@ describe('UA', function () {
})
it('recognizes chrome_mac', function () {
var ua = _detect(chrome_mac)
- expect(ua.isMobileDevice).to.be.false
- expect(!!ua.isIOS).to.be.false
- expect(!!ua.isAndroid).to.be.false
+ expect(ua.isMobileDevice).to.equal(false)
+ expect(!!ua.isIOS).to.equal(false)
+ expect(!!ua.isAndroid).to.equal(false)
expect(ua.osVersion).to.equal('')
expect(ua.browser).to.equal('chrome')
expect(ua.engine).to.equal('chrome')
@@ -409,9 +409,9 @@ describe('UA', function () {
})
it('recognizes ie_wp81', function () {
var ua = _detect(ie_wp81)
- expect(ua.isMobileDevice).to.be.false
- expect(!!ua.isIOS).to.be.false
- expect(!!ua.isAndroid).to.be.false
+ expect(ua.isMobileDevice).to.equal(false)
+ expect(!!ua.isIOS).to.equal(false)
+ expect(!!ua.isAndroid).to.equal(false)
expect(ua.osVersion).to.equal('')
expect(ua.browser).to.equal('ie-mobile')
expect(ua.engine).to.equal('')
@@ -419,9 +419,9 @@ describe('UA', function () {
})
it('recognizes edge_wp100', function () {
var ua = _detect(edge_wp100)
- expect(ua.isMobileDevice).to.be.false
- expect(!!ua.isIOS).to.be.false
- expect(!!ua.isAndroid).to.be.false
+ expect(ua.isMobileDevice).to.equal(false)
+ expect(!!ua.isIOS).to.equal(false)
+ expect(!!ua.isAndroid).to.equal(false)
expect(ua.osVersion).to.equal('')
expect(ua.browser).to.equal('edge')
expect(ua.engine).to.equal('edge')
diff --git a/test/test-url.js b/test/test-url.js
index 9afb48d..fc2d2bd 100644
--- a/test/test-url.js
+++ b/test/test-url.js
@@ -3,11 +3,11 @@ describe('URL', function () {
describe('_.url.parseQuery()', function () {
it('parses empty str to empty object', function () {
var query = ''
- expect(_.url.parseQuery(query)).to.deep.equal({})
+ expect(_.url.parseQuery(query)).to.eql({})
})
it('parses key/value pairs to object', function () {
var query = 'foo=1&bar=2&alice=&bob&chris=3'
- expect(_.url.parseQuery(query)).to.deep.equal({
+ expect(_.url.parseQuery(query)).to.eql({
foo: '1',
bar: '2',
alice: '',
@@ -17,7 +17,7 @@ describe('URL', function () {
})
it('decodes keys and values in query string', function () {
var query = 'foo=%20&bar=%2B&blah%3Dblah=1'
- expect(_.url.parseQuery(query)).to.deep.equal({
+ expect(_.url.parseQuery(query)).to.eql({
foo: ' ',
bar: '+',
'blah=blah': '1'
@@ -26,65 +26,163 @@ describe('URL', function () {
it('returns empty object if bad type of param', function () {
var arg
arg = undefined
- expect(_.url.parseQuery(arg)).to.deep.equal({})
+ expect(_.url.parseQuery(arg)).to.eql({})
arg = null
- expect(_.url.parseQuery(arg)).to.deep.equal({})
+ expect(_.url.parseQuery(arg)).to.eql({})
arg = 0
- expect(_.url.parseQuery(arg)).to.deep.equal({})
+ expect(_.url.parseQuery(arg)).to.eql({})
arg = true
- expect(_.url.parseQuery(arg)).to.deep.equal({})
+ expect(_.url.parseQuery(arg)).to.eql({})
arg = {}
- expect(_.url.parseQuery(arg)).to.deep.equal({})
+ expect(_.url.parseQuery(arg)).to.eql({})
arg = []
- expect(_.url.parseQuery(arg)).to.deep.equal({})
+ expect(_.url.parseQuery(arg)).to.eql({})
arg = it
- expect(_.url.parseQuery(arg)).to.deep.equal({})
+ expect(_.url.parseQuery(arg)).to.eql({})
})
})
describe('_.url.getParam()', function () {
- var _state = history.state || null
- var _url = location.href
+ var registeredTests = {}
+ var SANDBOX_FILE = '_sandbox.html'
+ var DUMMY_SRC = 'about:blank'
+ var $sandbox
+
+ function _getRandomStr() {
+ return (new Date().getTime() + Math.random()).toString(36)
+ }
+
+ // old IE don't support `history.replaceState()`, so we need a sandbox to run tests.
+ function _initSandbox() {
+ $sandbox = $('')
+ .attr({
+ src: DUMMY_SRC,
+ id: 'sandbox',
+ frameborder: 0
+ })
+ .css({
+ display: 'block',
+ visibility: 'visible',
+ height: 0
+ })
+ .appendTo(document.body)
+ }
+ function _resetSandbox() {
+ $sandbox.attr('src', DUMMY_SRC)
+ }
+ function _destroySandbox() {
+ $sandbox.remove()
+ }
+ function _getSandboxWindow() {
+ return $sandbox[0].contentWindow
+ }
+ function _startSandboxTest(queryString, keysToBeTested, fn) {
+ var testId = _getRandomStr()
+ registeredTests[testId] = fn
+ // set url to sandbox, this url will be tested when sandbox is ready
+ $sandbox.attr('src', SANDBOX_FILE + '?' + queryString)
+ // send test conditions to sandbox via `window.name`
+ _getSandboxWindow().name = JSON.stringify({
+ keysToBeTested: keysToBeTested,
+ testId: testId
+ })
+ }
+ function _listenSandboxMessage() {
+ var handler = function (ev) {
+ // recover complete data
+ var data = JSON.parse(ev.data || '{}')
+ var result = data.result || {}
+ _.each(data.emptyKeys || [], function (item) {
+ result[item] = undefined
+ })
+
+ var fn = registeredTests[data.testId]
+ if (_.isFunction(fn)) fn(result)
+ }
+ // note: `typeof window.attachEvent` returns 'object'
+ if ('attachEvent' in window) {
+ window.attachEvent('onmessage', handler)
+ } else {
+ window.addEventListener('message', handler, false)
+ }
+ }
+
+ before(function () {
+ _initSandbox()
+ _listenSandboxMessage()
+ })
after(function () {
- history.replaceState(_state, null, _url)
+ _destroySandbox()
})
- it('does basic functionality', function () {
- var url
- url = '?' + 'foo=1&bar=2&alice=&bob&chris=3'
- history.replaceState(_state, null, url)
- expect(_.url.getParam('foo')).to.equal('1')
- expect(_.url.getParam('bar')).to.equal('2')
- expect(_.url.getParam('alice')).to.equal('')
- expect(_.url.getParam('bob')).to.equal('')
- expect(_.url.getParam('chris')).to.equal('3')
+ afterEach(function () {
+ _resetSandbox()
})
- it('returns `undefined` if getting a missing param key', function () {
- var url
- url = '?'
- history.replaceState(_state, null, url)
- expect(_.url.getParam('foo')).to.be.undefined
- url = '?bar=1'
- history.replaceState(_state, null, url)
- expect(_.url.getParam('blah')).to.be.undefined
+
+ it('does basic functionality', function (done) {
+ this.timeout(5000)
+ var queryString = 'foo=1&bar=2&alice=&bob&chris=3'
+ var expectedResult = {
+ 'foo': '1',
+ 'bar': '2',
+ 'alice': '',
+ 'bob': '',
+ 'chris': '3'
+ }
+ var keysToBeTested = _.keys(expectedResult)
+ _startSandboxTest(queryString, keysToBeTested, function (result) {
+ expect(result).to.eql(expectedResult)
+ done()
+ })
+ })
+ it('returns `undefined` if query string is empty', function (done) {
+ this.timeout(5000)
+ var queryString = ''
+ var expectedResult = {
+ "foo": undefined,
+ "bar": undefined
+ }
+ var keysToBeTested = _.keys(expectedResult)
+ _startSandboxTest(queryString, keysToBeTested, function (result) {
+ expect(result).to.eql(expectedResult)
+ done()
+ })
+ })
+ it('returns `undefined` if getting a missing param key', function (done) {
+ this.timeout(5000)
+ var queryString = 'bar=1'
+ var expectedResult = {
+ "blah": undefined
+ }
+ var keysToBeTested = _.keys(expectedResult)
+ _startSandboxTest(queryString, keysToBeTested, function (result) {
+ expect(result).to.eql(expectedResult)
+ done()
+ })
})
it('returns `false` if bad type of param', function () {
var arg
arg = undefined
- expect(_.url.getParam(arg)).to.be.false
+ expect(_.url.getParam(arg)).to.equal(false)
arg = null
- expect(_.url.getParam(arg)).to.be.false
+ expect(_.url.getParam(arg)).to.equal(false)
arg = 0
- expect(_.url.getParam(arg)).to.be.false
+ expect(_.url.getParam(arg)).to.equal(false)
arg = true
- expect(_.url.getParam(arg)).to.be.false
+ expect(_.url.getParam(arg)).to.equal(false)
arg = {}
- expect(_.url.getParam(arg)).to.be.false
+ expect(_.url.getParam(arg)).to.equal(false)
arg = []
- expect(_.url.getParam(arg)).to.be.false
+ expect(_.url.getParam(arg)).to.equal(false)
arg = it
- expect(_.url.getParam(arg)).to.be.false
+ expect(_.url.getParam(arg)).to.equal(false)
})
it('re-parses if url changed', function () {
+ // skip this test case on ie9-
+ if (!('replaceState' in history)) return
+
+ var _state = history.state || null
+ var _url = location.href
+
var url
url = '?' + 'foo=%20&bar=%2B&blah%3Dblah=1'
history.replaceState(_state, null, url)
@@ -101,6 +199,9 @@ describe('URL', function () {
expect(_.url.getParam('foo')).to.equal(' ')
expect(_.url.getParam('bar')).to.equal('+')
expect(_.url.getParam('blah=blah')).to.equal('1')
+
+ // restore url
+ history.replaceState(_state, null, _url)
})
})