mirror of
https://github.com/docsifyjs/docsify.git
synced 2025-12-08 19:55:52 +00:00
Fix base element reset
This commit is contained in:
parent
d9e491a9e3
commit
a5a431f0c1
@ -32,7 +32,7 @@ beforeAll(async () => {
|
||||
fn(type, listener, options);
|
||||
}
|
||||
|
||||
// Add to default key arry to prevent removal during reset
|
||||
// Add to default key array to prevent removal during reset
|
||||
sideEffects[obj].keys.push('addEventListener');
|
||||
|
||||
// Replace addEventListener with mock
|
||||
@ -41,16 +41,16 @@ beforeAll(async () => {
|
||||
});
|
||||
|
||||
// Reset JSDOM. This attempts to remove side effects from tests, however it does
|
||||
// not reset all changes made to globals like the the window and document
|
||||
// not reset all changes made to globals like the window and document
|
||||
// objects. Tests requiring a full JSDOM reset should be stored in separate
|
||||
// files, which is only way to do a complete reset of JSDOM with Jest.
|
||||
// files, which is only way to do a complete JSDOM reset with Jest.
|
||||
beforeEach(async () => {
|
||||
const rootElm = document.documentElement;
|
||||
|
||||
// Remove attributes on root element
|
||||
[...rootElm.attributes].forEach(attr => rootElm.removeAttribute(attr.name));
|
||||
|
||||
// Remove elements (faster the setting innerHTML)
|
||||
// Remove elements (faster than setting innerHTML)
|
||||
while (rootElm.firstChild) {
|
||||
rootElm.removeChild(rootElm.firstChild);
|
||||
}
|
||||
@ -74,7 +74,7 @@ beforeEach(async () => {
|
||||
});
|
||||
|
||||
// Restore base elements
|
||||
rootElm.innerHTML = '<html><head></head><body></body></html>';
|
||||
rootElm.innerHTML = '<head></head><body></body>';
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user