Skip to content

Instantly share code, notes, and snippets.

@epreston
Created April 28, 2023 18:57
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/e87a8ab2850e809412a4374615b092e5 to your computer and use it in GitHub Desktop.
Save epreston/e87a8ab2850e809412a4374615b092e5 to your computer and use it in GitHub Desktop.
vitest - example sanity test for test environment
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
// ---------------------------------------------------------
describe('test environment', () => {
it('is working as expected', () => {
const obj = {};
expect(obj).toBeDefined();
expect(true).toBeTruthy();
});
it('defines vitest in the import.meta', () => {
expect(import.meta.vitest).toBeDefined();
});
});
// ---------------------------------------------------------
describe('type check', () => {
it('should be type string', () => {
expect(typeof '').toBe('string');
});
it('should be type number', () => {
expect(typeof 10).toBe('number');
});
it('should be type boolean', () => {
expect(typeof true).toBe('boolean');
});
it('should be type undefined', () => {
expect(typeof undefined).toBe('undefined');
});
it('should be type object', () => {
expect(typeof { foo: 'bar' }).toBe('object');
});
it('should be type function', () => {
expect(typeof function () {}).toBe('function');
});
it('should be type null', () => {
expect(typeof null).toBe('object');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment