刘光辉
118 分钟以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { mount } from '@vue/test-utils';
import { defineComponent, h, inject } from 'vue';
 
import { expect, it } from 'vitest';
 
import { provideUploadEditLoading, uploadEditLoadingKey } from './uploadEditLoading';
 
it('keeps a window busy until all attachment operations finish, with idempotent releases', () => {
  let loading!: ReturnType<typeof provideUploadEditLoading>;
  const finish: (() => void)[] = [];
  const child = defineComponent({
    setup() {
      finish.push(inject(uploadEditLoadingKey)!()!);
      return () => h('div');
    },
  });
  const wrapper = mount(
    defineComponent({
      setup() {
        loading = provideUploadEditLoading();
        return () => h('div', [h(child), h(child)]);
      },
    }),
  );
  try {
    expect(loading.value).toBe(true);
    finish[0]!();
    finish[0]!();
    expect(loading.value).toBe(true);
    finish[1]!();
    expect(loading.value).toBe(false);
  } finally {
    wrapper.unmount();
  }
});