Commit e1f6c928195791584f45001f6b494e1be859eaac
1 parent
1bf44ee0
optimization
Showing
1 changed file
with
42 additions
and
28 deletions
Show diff stats
test/unit/specs/affix.spec.js
| ... | ... | @@ -8,8 +8,10 @@ describe('Affix.vue', () => { |
| 8 | 8 | |
| 9 | 9 | it('should create a Affix component without slot', done => { |
| 10 | 10 | vm = createVue('<Affix></Affix>'); |
| 11 | - expect(vm.$el.children[0].tagName).to.equal('DIV'); | |
| 12 | - expect(vm.$el.children[0].className).to.equal(''); | |
| 11 | + const affix = vm.$el.children[0]; | |
| 12 | + | |
| 13 | + expect(affix.tagName).to.equal('DIV'); | |
| 14 | + expect(affix.className).to.equal(''); | |
| 13 | 15 | done(); |
| 14 | 16 | }); |
| 15 | 17 | |
| ... | ... | @@ -19,8 +21,10 @@ describe('Affix.vue', () => { |
| 19 | 21 | <span class="demo-affix">Fixed at the top</span> |
| 20 | 22 | </Affix> |
| 21 | 23 | `); |
| 22 | - expect(vm.$el.children[0].children[0].tagName).to.equal('SPAN'); | |
| 23 | - expect(vm.$el.children[0].children[0].className).to.equal('demo-affix'); | |
| 24 | + const slot = vm.$el.children[0].children[0]; | |
| 25 | + | |
| 26 | + expect(slot.tagName).to.equal('SPAN'); | |
| 27 | + expect(slot.className).to.equal('demo-affix'); | |
| 24 | 28 | done(); |
| 25 | 29 | }); |
| 26 | 30 | |
| ... | ... | @@ -33,14 +37,17 @@ describe('Affix.vue', () => { |
| 33 | 37 | <div style="width: 100%; height: 2000px"></div> |
| 34 | 38 | </div> |
| 35 | 39 | `, true); |
| 36 | - expect(vm.$el.children[0].children[0].classList.contains('ivu-affix')).to.false; | |
| 37 | - expect(vm.$el.children[0].children[0].style.top).to.equal(''); | |
| 38 | - expect(vm.$el.children[0].children[1].style.display).to.equal('none'); | |
| 40 | + const affix = vm.$el.children[0].children[0]; | |
| 41 | + const fakeBlock = vm.$el.children[0].children[1]; | |
| 42 | + | |
| 43 | + expect(affix.classList.contains('ivu-affix')).to.false; | |
| 44 | + expect(affix.style.top).to.equal(''); | |
| 45 | + expect(fakeBlock.style.display).to.equal('none'); | |
| 39 | 46 | window.scrollTo(0, 10000); |
| 40 | 47 | setTimeout(()=>{ |
| 41 | - expect(vm.$el.children[0].children[0].classList.contains('ivu-affix')).to.true; | |
| 42 | - expect(vm.$el.children[0].children[0].style.top).to.equal('20px'); | |
| 43 | - expect(vm.$el.children[0].children[1].style.display).to.equal(''); | |
| 48 | + expect(affix.classList.contains('ivu-affix')).to.true; | |
| 49 | + expect(affix.style.top).to.equal('20px'); | |
| 50 | + expect(fakeBlock.style.display).to.equal(''); | |
| 44 | 51 | done(); |
| 45 | 52 | }, 100); |
| 46 | 53 | }); |
| ... | ... | @@ -55,18 +62,20 @@ describe('Affix.vue', () => { |
| 55 | 62 | <div style="width: 100%; height: 2000px"></div> |
| 56 | 63 | </div> |
| 57 | 64 | `, true); |
| 58 | - expect(vm.$el.children[1].children[0].classList.contains('ivu-affix')).to.false; | |
| 59 | - expect(vm.$el.children[1].children[0].style.bottom).to.equal(''); | |
| 65 | + const affix = vm.$el.children[1].children[0]; | |
| 66 | + | |
| 67 | + expect(affix.classList.contains('ivu-affix')).to.false; | |
| 68 | + expect(affix.style.bottom).to.equal(''); | |
| 60 | 69 | // Affix component haven't run handleScroll function when component mounted in real dom. |
| 61 | 70 | // use scrollTo() to trigger scroll event. |
| 62 | 71 | window.scrollTo(0, 100); |
| 63 | 72 | setTimeout(()=>{ |
| 64 | - expect(vm.$el.children[1].children[0].classList.contains('ivu-affix')).to.true; | |
| 65 | - expect(vm.$el.children[1].children[0].style.bottom).to.equal('20px'); | |
| 73 | + expect(affix.classList.contains('ivu-affix')).to.true; | |
| 74 | + expect(affix.style.bottom).to.equal('20px'); | |
| 66 | 75 | window.scrollTo(0, 10000); |
| 67 | 76 | setTimeout(()=>{ |
| 68 | - expect(vm.$el.children[1].children[0].classList.contains('ivu-affix')).to.false; | |
| 69 | - expect(vm.$el.children[1].children[0].style.bottom).to.equal(''); | |
| 77 | + expect(affix.classList.contains('ivu-affix')).to.false; | |
| 78 | + expect(affix.style.bottom).to.equal(''); | |
| 70 | 79 | done(); |
| 71 | 80 | }, 100); |
| 72 | 81 | }, 100); |
| ... | ... | @@ -82,18 +91,20 @@ describe('Affix.vue', () => { |
| 82 | 91 | <div style="width: 100%; height: 2000px"></div> |
| 83 | 92 | </div> |
| 84 | 93 | `, true); |
| 85 | - expect(vm.$el.children[1].children[0].classList.contains('ivu-affix')).to.false; | |
| 86 | - expect(vm.$el.children[1].children[0].style.bottom).to.equal(''); | |
| 94 | + const affix = vm.$el.children[1].children[0]; | |
| 95 | + | |
| 96 | + expect(affix.classList.contains('ivu-affix')).to.false; | |
| 97 | + expect(affix.style.bottom).to.equal(''); | |
| 87 | 98 | // Affix component haven't run handleScroll function when component mounted in real dom. |
| 88 | 99 | // use scrollTo() to trigger scroll event. |
| 89 | 100 | window.scrollTo(0, 100); |
| 90 | 101 | setTimeout(()=>{ |
| 91 | - expect(vm.$el.children[1].children[0].classList.contains('ivu-affix')).to.true; | |
| 92 | - expect(vm.$el.children[1].children[0].style.bottom).to.equal('20px'); | |
| 102 | + expect(affix.classList.contains('ivu-affix')).to.true; | |
| 103 | + expect(affix.style.bottom).to.equal('20px'); | |
| 93 | 104 | window.scrollTo(0, 10000); |
| 94 | 105 | setTimeout(()=>{ |
| 95 | - expect(vm.$el.children[1].children[0].classList.contains('ivu-affix')).to.false; | |
| 96 | - expect(vm.$el.children[1].children[0].style.bottom).to.equal(''); | |
| 106 | + expect(affix.classList.contains('ivu-affix')).to.false; | |
| 107 | + expect(affix.style.bottom).to.equal(''); | |
| 97 | 108 | done(); |
| 98 | 109 | }, 100); |
| 99 | 110 | }, 100); |
| ... | ... | @@ -108,14 +119,17 @@ describe('Affix.vue', () => { |
| 108 | 119 | <div style="width: 100%; height: 2000px"></div> |
| 109 | 120 | </div> |
| 110 | 121 | `, true); |
| 111 | - expect(vm.$el.children[0].children[0].classList.contains('ivu-affix')).to.false; | |
| 112 | - expect(vm.$el.children[0].children[0].style.top).to.equal(''); | |
| 113 | - expect(vm.$el.children[0].children[1].style.display).to.equal('none'); | |
| 122 | + const affix = vm.$el.children[0].children[0]; | |
| 123 | + const fakeBlock = vm.$el.children[0].children[1]; | |
| 124 | + | |
| 125 | + expect(affix.classList.contains('ivu-affix')).to.false; | |
| 126 | + expect(affix.style.top).to.equal(''); | |
| 127 | + expect(fakeBlock.style.display).to.equal('none'); | |
| 114 | 128 | window.scrollTo(0, 10000); |
| 115 | 129 | setTimeout(()=>{ |
| 116 | - expect(vm.$el.children[0].children[0].classList.contains('ivu-affix')).to.true; | |
| 117 | - expect(vm.$el.children[0].children[0].style.top).to.equal('0px'); | |
| 118 | - expect(vm.$el.children[0].children[1].style.display).to.equal(''); | |
| 130 | + expect(affix.classList.contains('ivu-affix')).to.true; | |
| 131 | + expect(affix.style.top).to.equal('0px'); | |
| 132 | + expect(fakeBlock.style.display).to.equal(''); | |
| 119 | 133 | done(); |
| 120 | 134 | }, 100); |
| 121 | 135 | }); | ... | ... |