Vue-test-utils: test with portal-target pollutes the following test

Created on 4 Feb 2021  路  4Comments  路  Source: vuejs/vue-test-utils

Version

1.1.3

Reproduction link

https://github.com/BeniRupp/bug_portal-vue-target-already-exists

Steps to reproduce

Run the unit test example.spec.js. The second test will throw a warning.

What is expected?

The warning target xxx already exists should not be thrown, since each test uses its own localVue instance. There should only exist one portal-target with the name "berlin" in the second test.

What is actually happening?

The first test pollutes the second test because the portal-target with the given name is already present.

bug

All 4 comments

hmmm very weird! Looking into this, I don't see any obvious cause...

I don't know much about portal-vue but looks like you need to destroy the wrapper to unregister the target after each test. See here https://github.com/LinusBorg/portal-vue/blob/da8fed161051cddbeff68fb9907f750adeb2cdb5/src/components/portal-target.tsx#L53

I did w.destroy() after each of your tests, and the warning is now gone.

You could probably use the afterDestroy feature to make this more convenient.

I am not sure this is a bug in Test Utils or not. I feel like localVue should have bee enough so you don't need to do this, but I am not clear on how portal-vue works internally with registering targets. Maybe @LinusBorg has some ideas, he created the portal-vue library.

Yeah this is an unfortunate side-effect of a feature I implemented a while back, it's supposed to warn during dev so you don't accidentally define two targets with the same name.

could be improved/saolved in portal-vue, it's not a bug in test-utils.

Workaround, as mentioned, is to properly unmount after each test.

@lmiller1990 and @LinusBorg thank you very much for your time and the fast response! 馃憦

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vilarinholeo picture vilarinholeo  路  3Comments

robcresswell picture robcresswell  路  3Comments

alexanderstudte picture alexanderstudte  路  3Comments

AustinGil picture AustinGil  路  3Comments

vwxyutarooo picture vwxyutarooo  路  3Comments