Skip to content

Commit

Permalink
test: Tweak test utils tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmilton committed Sep 27, 2023
1 parent 07027f5 commit 0df9cba
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion test/unit/test-utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { afterEach, describe, expect, spyOn, test } from 'bun:test';
import { Test } from '../TestComponent';
import { cleanup, render } from './utils';
import { cleanup, consoleSpy, render } from './utils';

describe('render (no call)', () => {
test('is a function', () => {
expect(render).toBeInstanceOf(Function);
});

test('takes a single argument', () => {
expect(render).toHaveLength(1);
});
});

describe('render', () => {
afterEach(cleanup);
Expand Down Expand Up @@ -89,6 +99,14 @@ describe('render', () => {
});

describe('cleanup', () => {
test('is a function', () => {
expect(cleanup).toBeInstanceOf(Function);
});

test('takes no arguments', () => {
expect(cleanup).toHaveLength(0);
});

test('throws when there are no rendered components', () => {
expect(() => cleanup()).toThrow();
});
Expand Down Expand Up @@ -124,3 +142,39 @@ describe('cleanup', () => {
document.body.textContent = '';
});
});

describe('consoleSpy', () => {
test('is a function', () => {
expect(consoleSpy).toBeInstanceOf(Function);
});

test('takes no arguments', () => {
expect(consoleSpy).toHaveLength(0);
});

test('returns a function', () => {
const checkConsoleCalls = consoleSpy();
expect(checkConsoleCalls).toBeInstanceOf(Function);
checkConsoleCalls();
});

test('returned function takes no arguments', () => {
const checkConsoleCalls = consoleSpy();
expect(checkConsoleCalls).toHaveLength(0);
checkConsoleCalls();
});

test('passes when no console methods are called', () => {
const checkConsoleCalls = consoleSpy();
checkConsoleCalls();
});

// FIXME: How to test this?
test.skip('fails when console methods are called', () => {
const checkConsoleCalls = consoleSpy();
console.log('a');
console.warn('b');
console.error('c');
checkConsoleCalls();
});
});

0 comments on commit 0df9cba

Please sign in to comment.