fix(Toast): failed to reopen when using get-container (#7032)

This commit is contained in:
neverland 2020-08-21 20:53:21 +08:00 committed by GitHub
parent 60ce7e048e
commit a78a7b6aa8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -43,12 +43,18 @@ function parseOptions(message) {
return { message };
}
function isInDocument(element) {
return document.body.contains(element);
}
function createInstance() {
/* istanbul ignore if */
if (isServer) {
return {};
}
queue = queue.filter((item) => isInDocument(item.$el));
if (!queue.length || multiple) {
const toast = new (Vue.extend(VueToast))({
el: document.createElement('div'),

View File

@ -74,26 +74,31 @@ test('icon-prefix prop', async () => {
expect(toast.$el.outerHTML).toMatchSnapshot();
});
test('clear toast', () => {
const toast1 = Toast();
test('clear toast', async () => {
const toast1 = Toast('1');
await later();
expect(toast1.value).toBeTruthy();
Toast.clear();
expect(toast1.value).toBeFalsy();
Toast.allowMultiple();
const toast2 = Toast('2');
await later();
const toast3 = Toast('3');
await later();
Toast.clear(true);
expect(toast2.value).toBeFalsy();
expect(toast3.value).toBeFalsy();
Toast.allowMultiple(false);
});
test('clear multiple toast', () => {
test('clear multiple toast', async () => {
Toast.allowMultiple();
Toast.clear(true);
const toast1 = Toast.success('1');
await later();
const toast2 = Toast.success('2');
await later();
Toast.clear();
expect(toast1.value).toBeFalsy();
expect(toast2.value).toBeTruthy();