11/* eslint-disable no-eval */
2- import { injectCSS , updateCSS , removeCSS } from '../src/Dom/dynamicCSS' ;
2+ import {
3+ injectCSS ,
4+ updateCSS ,
5+ removeCSS ,
6+ clearContainerCache ,
7+ } from '../src/Dom/dynamicCSS' ;
38
49const TEST_STYLE = '.bamboo { context: "light" }' ;
510
@@ -171,15 +176,20 @@ describe('dynamicCSS', () => {
171176
172177 describe ( 'qiankun' , ( ) => {
173178 let originAppendChild : typeof document . head . appendChild ;
179+ let originRemoveChild : typeof document . head . removeChild ;
174180 let targetContainer : HTMLElement ;
175181
176182 beforeAll ( ( ) => {
183+ clearContainerCache ( ) ;
177184 originAppendChild = document . head . appendChild ;
185+ originRemoveChild = document . head . removeChild ;
178186 document . head . appendChild = ele => targetContainer . appendChild ( ele ) ;
187+ document . head . removeChild = ele => targetContainer . removeChild ( ele ) ;
179188 } ) ;
180189
181190 afterAll ( ( ) => {
182191 document . head . appendChild = originAppendChild ;
192+ document . head . removeChild = originRemoveChild ;
183193 } ) ;
184194
185195 it ( 'updateCSS' , ( ) => {
@@ -191,7 +201,12 @@ describe('dynamicCSS', () => {
191201 expect ( document . head . contains ( firstStyle ) ) . toBeFalsy ( ) ;
192202 expect ( targetContainer . contains ( firstStyle ) ) . toBeTruthy ( ) ;
193203
194- // Mock qiankun uninstall & reinstall
204+ // Mock qiankun uninstall
205+ removeCSS ( 'qiankun' ) ;
206+ expect ( document . head . contains ( firstStyle ) ) . toBeFalsy ( ) ;
207+ expect ( targetContainer . contains ( firstStyle ) ) . toBeFalsy ( ) ;
208+
209+ // Mock qiankun reinstall
195210 document . body . removeChild ( targetContainer ) ;
196211 targetContainer = document . createElement ( 'div' ) ;
197212 document . body . appendChild ( targetContainer ) ;
0 commit comments