Skip to content

Instantly share code, notes, and snippets.

@Tahul
Last active July 3, 2024 17:13
Show Gist options
  • Save Tahul/d98ec315eeaa24ab691649783f25dafd to your computer and use it in GitHub Desktop.
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
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