|
| 1 | +import { isVue3 } from '../vue' |
1 | 2 | import { mount } from '@vue/test-utils' |
2 | 3 | import { listenersMixin } from './listeners' |
3 | 4 |
|
@@ -133,17 +134,41 @@ describe('mixins > listeners', () => { |
133 | 134 | const App1 = { |
134 | 135 | components: { Input1 }, |
135 | 136 | props: ['listenFocus1', 'listenFocus2'], |
| 137 | + methods: { |
| 138 | + emit1($event) { |
| 139 | + if (this.listenFocus1) { |
| 140 | + this.$emit('focus1', $event) |
| 141 | + } |
| 142 | + }, |
| 143 | + emit2($event) { |
| 144 | + if (this.listenFocus2) { |
| 145 | + this.$emit('focus2', $event) |
| 146 | + } |
| 147 | + } |
| 148 | + }, |
136 | 149 | template: `<div> |
137 | | - <Input1 @focus="listenFocus1 ? $emit('focus1', $event) : () => {}" /> |
138 | | - <Input1 @focus="listenFocus2 ? $emit('focus2', $event) : () => {}" /> |
| 150 | + <Input1 @focus="emit1" /> |
| 151 | + <Input1 @focus="emit2" /> |
139 | 152 | </div>` |
140 | 153 | } |
141 | 154 | const App2 = { |
142 | 155 | components: { Input2 }, |
143 | 156 | props: ['listenFocus1', 'listenFocus2'], |
| 157 | + methods: { |
| 158 | + emit1($event) { |
| 159 | + if (this.listenFocus1) { |
| 160 | + this.$emit('focus1', $event) |
| 161 | + } |
| 162 | + }, |
| 163 | + emit2($event) { |
| 164 | + if (this.listenFocus2) { |
| 165 | + this.$emit('focus2', $event) |
| 166 | + } |
| 167 | + } |
| 168 | + }, |
144 | 169 | template: `<div> |
145 | | - <Input2 @focus="listenFocus1 ? $emit('focus1', $event) : () => {}" /> |
146 | | - <Input2 @focus="listenFocus2 ? $emit('focus2', $event) : () => {}" /> |
| 170 | + <Input2 @focus="emit1" /> |
| 171 | + <Input2 @focus="emit2" /> |
147 | 172 | </div>` |
148 | 173 | } |
149 | 174 |
|
@@ -172,15 +197,15 @@ describe('mixins > listeners', () => { |
172 | 197 | expect(wrapper1.emitted().focus1).toBeTruthy() |
173 | 198 | expect(wrapper1.emitted().focus2).not.toBeTruthy() |
174 | 199 | // Both `Input1`'s are re-rendered (See: https://github.com/vuejs/vue/issues/7257) |
175 | | - expect(input1RenderCount).toBe(4) |
| 200 | + expect(input1RenderCount).toBe(isVue3 ? 2 : 4) |
176 | 201 |
|
177 | 202 | // Enable focus events for the second input and trigger it |
178 | 203 | await wrapper1.setProps({ listenFocus2: true }) |
179 | 204 | await $inputs1.at(1).trigger('focus') |
180 | 205 | expect(wrapper1.emitted().focus1).toBeTruthy() |
181 | 206 | expect(wrapper1.emitted().focus2).toBeTruthy() |
182 | 207 | // Both `Input1`'s are re-rendered (See: https://github.com/vuejs/vue/issues/7257) |
183 | | - expect(input1RenderCount).toBe(6) |
| 208 | + expect(input1RenderCount).toBe(isVue3 ? 2 : 6) |
184 | 209 |
|
185 | 210 | // --- `Input2` tests --- |
186 | 211 |
|
|
0 commit comments