You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by da...@apache.org on 2017/07/20 08:29:36 UTC
[06/50] incubator-weex git commit: * [html5] add unit test
* [html5] add unit test
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/0378b369
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/0378b369
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/0378b369
Branch: refs/heads/0.15-dev
Commit: 0378b36973b9107b61d31b49a65efd2f480eb32b
Parents: 7baff11
Author: erha19 <fa...@gmail.com>
Authored: Mon Jul 10 15:03:44 2017 +0800
Committer: erha19 <fa...@gmail.com>
Committed: Mon Jul 10 15:03:44 2017 +0800
----------------------------------------------------------------------
html5/test/render/vue/utils/func.js | 135 +++++++++++++++++++++++++++++++
1 file changed, 135 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/0378b369/html5/test/render/vue/utils/func.js
----------------------------------------------------------------------
diff --git a/html5/test/render/vue/utils/func.js b/html5/test/render/vue/utils/func.js
index 246178d..1c50bac 100644
--- a/html5/test/render/vue/utils/func.js
+++ b/html5/test/render/vue/utils/func.js
@@ -164,5 +164,140 @@ describe('utils', function () {
expect(loopArray([1, 2, 3], -1)).to.be.deep.equal([2, 3, 1])
expect(loopArray([1, 2, 3], 0)).to.be.deep.equal([1, 2, 3])
})
+ it('cached', function () {
+ expect(utils.cached).to.be.a('function')
+ })
+ it('camelize', function () {
+ const {
+ camelize
+ } = utils
+ expect(camelize).to.be.a('function')
+ expect(camelize('')).to.be.equal('')
+ expect(camelize('dispaly')).to.be.equal('dispaly')
+ expect(camelize('-webkit-transform')).to.be.equal('WebkitTransform')
+ expect(camelize('text-overflow')).to.be.equal('textOverflow')
+ expect(camelize('a-b-c-d')).to.be.equal('aBCD')
+ })
+ it('camelizeKeys', function () {
+ const {
+ camelizeKeys
+ } = utils
+ const camelizeobj = {
+ dispaly: 'none',
+ '-webkit-transform': 'all 1s ease'
+ }
+ const shouldBe = camelizeKeys(camelizeobj)
+ const expected = {
+ dispaly: 'none',
+ WebkitTransform: 'all 1s ease'
+ }
+ expect(camelizeKeys).to.be.a('function')
+ expect(shouldBe).to.be.deep.equal(expected)
+ })
+ it('capitalize', function () {
+ const {
+ capitalize
+ } = utils
+ expect(capitalize).to.be.a('function')
+ expect(capitalize('')).to.be.equal('')
+ expect(capitalize('string')).to.be.equal('String')
+ expect(capitalize('string object')).to.be.equal('String object')
+ expect(capitalize('[string object]')).to.be.equal('[string object]')
+ expect(capitalize('I have an apple')).to.be.equal('I have an apple')
+ })
+ it('hyphenate', function () {
+ const {
+ hyphenate
+ } = utils
+ expect(hyphenate).to.be.a('function')
+ expect(hyphenate('')).to.be.equal('')
+ expect(hyphenate('dispaly')).to.be.equal('dispaly')
+ expect(hyphenate('WebkitTransform')).to.be.equal('webkit-transform')
+ expect(hyphenate('textOverflow')).to.be.equal('text-overflow')
+ expect(hyphenate('aBCD')).to.be.equal('a-b-c-d')
+ })
+ it('hyphenateKeys', function () {
+ const {
+ hyphenateKeys
+ } = utils
+ const hyphenateobj = {
+ dispaly: 'none',
+ WebkitTransform: 'all 1s ease'
+ }
+ const shouldBe = hyphenateKeys(hyphenateobj)
+ const expected = {
+ dispaly: 'none',
+ 'webkit-transform': 'all 1s ease'
+ }
+ expect(hyphenateKeys).to.be.a('function')
+ expect(shouldBe).to.be.deep.equal(expected)
+ })
+ it('hyphenateStyleKeys', function () {
+ const {
+ hyphenateStyleKeys
+ } = utils
+ const hyphenateStyleObj = {
+ dispaly: 'none',
+ 'webkit-transform': 'all 1s ease'
+ }
+ const shouldBe = hyphenateStyleKeys(hyphenateStyleObj)
+ const expected = {
+ dispaly: 'none',
+ '-webkit-transform': 'all 1s ease'
+ }
+ expect(hyphenateStyleKeys).to.be.a('function')
+ expect(shouldBe).to.be.deep.equal(expected)
+ })
+ it('camelToKebab', function () {
+ const {
+ camelToKebab
+ } = utils
+ expect(camelToKebab).to.be.a('function')
+ expect(camelToKebab('')).to.be.equal('')
+ expect(camelToKebab('ABC')).to.be.equal('-a-b-c')
+ })
+ it('appendCss', function () {
+ const {
+ appendCss
+ } = utils
+ const cssid = 'append-test'
+ const css = '.test{font-size:12px}'
+ expect(appendCss).to.be.a('function')
+ appendCss(css, cssid, true)
+ let handler = document.querySelector('#' + cssid)
+ expect(handler.textContent).to.be.equal(css)
+ const anothercss = '.test2{font-size:16px}'
+ appendCss(anothercss, cssid, true)
+ handler = document.querySelector('#' + cssid)
+ expect(handler.textContent).to.be.equal(anothercss)
+ })
+ it('nextFrame', function (done) {
+ const {
+ nextFrame
+ } = utils
+ let shouldBe
+ const expected = 'test'
+ const cb = function () {
+ shouldBe = expected
+ }
+ expect(nextFrame).to.be.a('function')
+ this.clock.restore()
+ nextFrame(cb)
+ setTimeout(() => {
+ expect(shouldBe).to.be.equal(expected)
+ done()
+ }, 10)
+ })
+ it('toCSSText', function () {
+ const {
+ toCSSText
+ } = utils
+ const expected = 'font-size:12px;'
+ const shouldBe = toCSSText({
+ 'font-size': '12px'
+ })
+ expect(toCSSText).to.be.a('function')
+ expect(shouldBe).to.be.equal(expected)
+ })
})
})