Skip to content

Instantly share code, notes, and snippets.

@epreston
Created April 28, 2023 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epreston/3922c1b6a5aa617790f6e31578bf63eb to your computer and use it in GitHub Desktop.
Save epreston/3922c1b6a5aa617790f6e31578bf63eb to your computer and use it in GitHub Desktop.
vitest - example test file structure for browser context testing with jsdom
// @vitest-environment jsdom
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
// ---------------------------------------------------------
// import { itemsToMock } from '../src/testDependency.js';
// ---------------------------------------------------------
// vi.mock('../src/testDependency.js');
// ---------------------------------------------------------
// import { itemBeingTested } from '../src/testTarget.js';
// ---------------------------------------------------------
describe('JSDom Test Environment', () => {
it('is working as expected', () => {
expect(document).toBeDefined();
expect(window).toBeDefined();
const divEl = document.createElement('div');
expect(divEl).toBeDefined();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment