+ [html5] update lazyload 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/5521172b Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/5521172b Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/5521172b Branch: refs/heads/0.15-dev Commit: 5521172b0a2d7b3ce74fb4e7596a9778c5807825 Parents: 1bbe886 Author: erha19 <faterr...@gmail.com> Authored: Thu Jul 13 13:17:18 2017 +0800 Committer: erha19 <faterr...@gmail.com> Committed: Thu Jul 13 13:17:18 2017 +0800 ---------------------------------------------------------------------- html5/test/render/vue/utils/lazyload.js | 42 +++++++++++++++++----------- 1 file changed, 25 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/5521172b/html5/test/render/vue/utils/lazyload.js ---------------------------------------------------------------------- diff --git a/html5/test/render/vue/utils/lazyload.js b/html5/test/render/vue/utils/lazyload.js index 8576ffc..59c5593 100644 --- a/html5/test/render/vue/utils/lazyload.js +++ b/html5/test/render/vue/utils/lazyload.js @@ -25,34 +25,42 @@ describe('utils', function () { after(() => { this.clock.restore() }) - // it('applySrc', () => { - - // }) + it('applySrc', () => { + const { + applySrc + } = lazyload + const node = document.createElement('figure') + node.setAttribute('img-src', 'http://via.placeholder.com/1x1') + node.setAttribute('img-placeholder', 'http://via.placeholder.com/2x2') + document.body.appendChild(node) + expect(applySrc(node, '')).to.be.a('undefined') + expect(node.attributes[0].name).to.be.equal('img-src') + }) it('fireLazyload', () => { - // const { - // fireLazyload - // } = lazyload - // const node = document.createElement('figure') - // node.setAttribute('img-src', 'http://some-domain/image-src.jpg') - // node.setAttribute('img-placeholder', 'http://some-domain/image-placeholder') - // document.body.appendChild(node) - // fireLazyload(node, true) - // expect(node.style.backgroundImage).to.be.equal('url(http://some-domain/image-src.jpg)') + const { + fireLazyload + } = lazyload + const node = document.createElement('figure') + node.setAttribute('img-src', 'http://via.placeholder.com/1x1') + node.setAttribute('img-placeholder', 'http://via.placeholder.com/2x2') + document.body.appendChild(node) + fireLazyload(node, true) + expect(node.style.backgroundImage).to.be.equal('url(http://via.placeholder.com/1x1)') }) it('getThrottleLazyload', () => { const { getThrottleLazyload } = lazyload const node = document.createElement('figure') - node.setAttribute('img-src', 'http://some-domain/image-src.jpg') - node.setAttribute('img-placeholder', 'http://some-domain/image-placeholder') + node.setAttribute('img-src', 'http://via.placeholder.com/1x1') + node.setAttribute('img-placeholder', 'http://via.placeholder.com/2x2') document.body.appendChild(node) const throttle = getThrottleLazyload(100, node) expect(throttle).to.be.a('function') throttle() - // this.clock.tick(100) - // console.log(node.style.backgroundImage) - // expect(node.style.backgroundImage).to.be.equal('url(http://localhost:9876/img-src.jpg)') + // this.clock.tick(100) + // console.log(node.style.backgroundImage) + // expect(node.style.backgroundImage).to.be.equal('url(http://localhost:9876/img-src.jpg)') }) }) })