|
1 | 1 | import { |
| 2 | + VaporTransition, |
2 | 3 | child, |
| 4 | + createComponent, |
3 | 5 | createIf, |
4 | 6 | insert, |
5 | 7 | renderEffect, |
@@ -185,6 +187,101 @@ describe('createIf', () => { |
185 | 187 | expect(onUpdated).toHaveBeenCalledTimes(2) |
186 | 188 | }) |
187 | 189 |
|
| 190 | + test('should not set branch block key without Transition or KeepAlive', async () => { |
| 191 | + const show = ref(true) |
| 192 | + const t0 = template('<div>foo</div>') |
| 193 | + const t1 = template('<div>bar</div>') |
| 194 | + let branch!: any |
| 195 | + |
| 196 | + const { host } = define(() => |
| 197 | + createIf( |
| 198 | + () => show.value, |
| 199 | + () => (branch = t0()), |
| 200 | + () => (branch = t1()), |
| 201 | + undefined, |
| 202 | + undefined, |
| 203 | + 0, |
| 204 | + ), |
| 205 | + ).render() |
| 206 | + |
| 207 | + expect(host.innerHTML).toBe('<div>foo</div><!--if-->') |
| 208 | + expect(branch.$key).toBeUndefined() |
| 209 | + |
| 210 | + show.value = false |
| 211 | + await nextTick() |
| 212 | + |
| 213 | + expect(host.innerHTML).toBe('<div>bar</div><!--if-->') |
| 214 | + expect(branch.$key).toBeUndefined() |
| 215 | + }) |
| 216 | + |
| 217 | + test('should not set branch block key outside Transition after Transition is used', async () => { |
| 218 | + const show = ref(true) |
| 219 | + const transitionChild = template('<span>transition</span>') |
| 220 | + const t0 = template('<div>foo</div>') |
| 221 | + const t1 = template('<div>bar</div>') |
| 222 | + let branch!: any |
| 223 | + |
| 224 | + const { host } = define(() => [ |
| 225 | + createComponent( |
| 226 | + VaporTransition, |
| 227 | + null, |
| 228 | + { |
| 229 | + default: () => transitionChild(), |
| 230 | + }, |
| 231 | + true, |
| 232 | + ), |
| 233 | + createIf( |
| 234 | + () => show.value, |
| 235 | + () => (branch = t0()), |
| 236 | + () => (branch = t1()), |
| 237 | + undefined, |
| 238 | + undefined, |
| 239 | + 0, |
| 240 | + ), |
| 241 | + ]).render() |
| 242 | + |
| 243 | + expect(host.innerHTML).toBe( |
| 244 | + '<span>transition</span><div>foo</div><!--if-->', |
| 245 | + ) |
| 246 | + expect(branch.$key).toBeUndefined() |
| 247 | + |
| 248 | + show.value = false |
| 249 | + await nextTick() |
| 250 | + |
| 251 | + expect(host.innerHTML).toBe( |
| 252 | + '<span>transition</span><div>bar</div><!--if-->', |
| 253 | + ) |
| 254 | + expect(branch.$key).toBeUndefined() |
| 255 | + }) |
| 256 | + |
| 257 | + test('should set branch block key inside Transition', () => { |
| 258 | + const show = ref(true) |
| 259 | + const t0 = template('<div>foo</div>') |
| 260 | + const t1 = template('<div>bar</div>') |
| 261 | + let branch!: any |
| 262 | + |
| 263 | + define(() => |
| 264 | + createComponent( |
| 265 | + VaporTransition, |
| 266 | + null, |
| 267 | + { |
| 268 | + default: () => |
| 269 | + createIf( |
| 270 | + () => show.value, |
| 271 | + () => (branch = t0()), |
| 272 | + () => (branch = t1()), |
| 273 | + undefined, |
| 274 | + undefined, |
| 275 | + 0, |
| 276 | + ), |
| 277 | + }, |
| 278 | + true, |
| 279 | + ), |
| 280 | + ).render() |
| 281 | + |
| 282 | + expect(branch.$key).toBe('00') |
| 283 | + }) |
| 284 | + |
188 | 285 | // vapor custom directives have no lifecycle hooks. |
189 | 286 | test.todo('should work with directive hooks', async () => { |
190 | 287 | const calls: string[] = [] |
|
0 commit comments