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 +8,10 @@ describe('Affix.vue', () => { | ||
8 | 8 | ||
9 | it('should create a Affix component without slot', done => { | 9 | it('should create a Affix component without slot', done => { |
10 | vm = createVue('<Affix></Affix>'); | 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 | done(); | 15 | done(); |
14 | }); | 16 | }); |
15 | 17 | ||
@@ -19,8 +21,10 @@ describe('Affix.vue', () => { | @@ -19,8 +21,10 @@ describe('Affix.vue', () => { | ||
19 | <span class="demo-affix">Fixed at the top</span> | 21 | <span class="demo-affix">Fixed at the top</span> |
20 | </Affix> | 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 | done(); | 28 | done(); |
25 | }); | 29 | }); |
26 | 30 | ||
@@ -33,14 +37,17 @@ describe('Affix.vue', () => { | @@ -33,14 +37,17 @@ describe('Affix.vue', () => { | ||
33 | <div style="width: 100%; height: 2000px"></div> | 37 | <div style="width: 100%; height: 2000px"></div> |
34 | </div> | 38 | </div> |
35 | `, true); | 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 | window.scrollTo(0, 10000); | 46 | window.scrollTo(0, 10000); |
40 | setTimeout(()=>{ | 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 | done(); | 51 | done(); |
45 | }, 100); | 52 | }, 100); |
46 | }); | 53 | }); |
@@ -55,18 +62,20 @@ describe('Affix.vue', () => { | @@ -55,18 +62,20 @@ describe('Affix.vue', () => { | ||
55 | <div style="width: 100%; height: 2000px"></div> | 62 | <div style="width: 100%; height: 2000px"></div> |
56 | </div> | 63 | </div> |
57 | `, true); | 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 | // Affix component haven't run handleScroll function when component mounted in real dom. | 69 | // Affix component haven't run handleScroll function when component mounted in real dom. |
61 | // use scrollTo() to trigger scroll event. | 70 | // use scrollTo() to trigger scroll event. |
62 | window.scrollTo(0, 100); | 71 | window.scrollTo(0, 100); |
63 | setTimeout(()=>{ | 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 | window.scrollTo(0, 10000); | 75 | window.scrollTo(0, 10000); |
67 | setTimeout(()=>{ | 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 | done(); | 79 | done(); |
71 | }, 100); | 80 | }, 100); |
72 | }, 100); | 81 | }, 100); |
@@ -82,18 +91,20 @@ describe('Affix.vue', () => { | @@ -82,18 +91,20 @@ describe('Affix.vue', () => { | ||
82 | <div style="width: 100%; height: 2000px"></div> | 91 | <div style="width: 100%; height: 2000px"></div> |
83 | </div> | 92 | </div> |
84 | `, true); | 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 | // Affix component haven't run handleScroll function when component mounted in real dom. | 98 | // Affix component haven't run handleScroll function when component mounted in real dom. |
88 | // use scrollTo() to trigger scroll event. | 99 | // use scrollTo() to trigger scroll event. |
89 | window.scrollTo(0, 100); | 100 | window.scrollTo(0, 100); |
90 | setTimeout(()=>{ | 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 | window.scrollTo(0, 10000); | 104 | window.scrollTo(0, 10000); |
94 | setTimeout(()=>{ | 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 | done(); | 108 | done(); |
98 | }, 100); | 109 | }, 100); |
99 | }, 100); | 110 | }, 100); |
@@ -108,14 +119,17 @@ describe('Affix.vue', () => { | @@ -108,14 +119,17 @@ describe('Affix.vue', () => { | ||
108 | <div style="width: 100%; height: 2000px"></div> | 119 | <div style="width: 100%; height: 2000px"></div> |
109 | </div> | 120 | </div> |
110 | `, true); | 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 | window.scrollTo(0, 10000); | 128 | window.scrollTo(0, 10000); |
115 | setTimeout(()=>{ | 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 | done(); | 133 | done(); |
120 | }, 100); | 134 | }, 100); |
121 | }); | 135 | }); |