Skip to content

Instantly share code, notes, and snippets.

@Tahul
Last active August 3, 2022 22:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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