Last active
July 3, 2024 17:13
-
-
Save Tahul/d98ec315eeaa24ab691649783f25dafd to your computer and use it in GitHub Desktop.
[Jest Reset Dom After Each Test] A simple snippet to reset the JSDOM after each single test #jest #reset #dom #jsdom #tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('my test suite', () => { | |
afterEach(() => { | |
document.getElementsByTagName('html')[0].innerHTML = ''; | |
}); | |
it('your test here', () => { | |
document.getElementsByTagName('html')[0].innerHTML = 'Your dom manipulation here'; | |
}); | |
it('your second test here', () => { | |
// Document will be fresh again here. | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment