mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Toast): failed to reopen when using get-container (#7032)
This commit is contained in:
parent
60ce7e048e
commit
a78a7b6aa8
@ -43,12 +43,18 @@ function parseOptions(message) {
|
|||||||
return { message };
|
return { message };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isInDocument(element) {
|
||||||
|
return document.body.contains(element);
|
||||||
|
}
|
||||||
|
|
||||||
function createInstance() {
|
function createInstance() {
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (isServer) {
|
if (isServer) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
queue = queue.filter((item) => isInDocument(item.$el));
|
||||||
|
|
||||||
if (!queue.length || multiple) {
|
if (!queue.length || multiple) {
|
||||||
const toast = new (Vue.extend(VueToast))({
|
const toast = new (Vue.extend(VueToast))({
|
||||||
el: document.createElement('div'),
|
el: document.createElement('div'),
|
||||||
|
@ -74,26 +74,31 @@ test('icon-prefix prop', async () => {
|
|||||||
expect(toast.$el.outerHTML).toMatchSnapshot();
|
expect(toast.$el.outerHTML).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('clear toast', () => {
|
test('clear toast', async () => {
|
||||||
const toast1 = Toast();
|
const toast1 = Toast('1');
|
||||||
|
await later();
|
||||||
expect(toast1.value).toBeTruthy();
|
expect(toast1.value).toBeTruthy();
|
||||||
Toast.clear();
|
Toast.clear();
|
||||||
expect(toast1.value).toBeFalsy();
|
expect(toast1.value).toBeFalsy();
|
||||||
|
|
||||||
Toast.allowMultiple();
|
Toast.allowMultiple();
|
||||||
const toast2 = Toast('2');
|
const toast2 = Toast('2');
|
||||||
|
await later();
|
||||||
const toast3 = Toast('3');
|
const toast3 = Toast('3');
|
||||||
|
await later();
|
||||||
Toast.clear(true);
|
Toast.clear(true);
|
||||||
expect(toast2.value).toBeFalsy();
|
expect(toast2.value).toBeFalsy();
|
||||||
expect(toast3.value).toBeFalsy();
|
expect(toast3.value).toBeFalsy();
|
||||||
Toast.allowMultiple(false);
|
Toast.allowMultiple(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('clear multiple toast', () => {
|
test('clear multiple toast', async () => {
|
||||||
Toast.allowMultiple();
|
Toast.allowMultiple();
|
||||||
Toast.clear(true);
|
Toast.clear(true);
|
||||||
const toast1 = Toast.success('1');
|
const toast1 = Toast.success('1');
|
||||||
|
await later();
|
||||||
const toast2 = Toast.success('2');
|
const toast2 = Toast.success('2');
|
||||||
|
await later();
|
||||||
Toast.clear();
|
Toast.clear();
|
||||||
expect(toast1.value).toBeFalsy();
|
expect(toast1.value).toBeFalsy();
|
||||||
expect(toast2.value).toBeTruthy();
|
expect(toast2.value).toBeTruthy();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user