Skip to content

Commit

Permalink
test: add cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kabeep committed May 8, 2024
1 parent 08710aa commit fc19626
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
15 changes: 15 additions & 0 deletions test/helpers/boundary.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect, test } from 'vitest';
import boundary from '../../src/helpers/boundary';
import { Failure } from '../../src/utils';

test('boundary - should return a Failure object when the inner function throws an error', async () => {
function innerFunction() {
throw new Error('Test error');
}

const wrappedFunction = boundary(innerFunction);

const result = await wrappedFunction();

expect(result).toStrictEqual(new Failure('Test error'));
});
15 changes: 15 additions & 0 deletions test/utils/get-columns.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { stdout } from 'node:process';
import { expect, test } from 'vitest';
import getColumns from '../../src/utils/get-columns';

test('getColumns - should return the number of columns', () => {
stdout.columns = 80;
const result = getColumns();
expect(result).toBe(80);
});

test('getColumns - should return 0 if stdout.columns is undefined', () => {
stdout.columns = undefined;
const result = getColumns();
expect(result).toBe(0);
});
17 changes: 17 additions & 0 deletions test/utils/is-error.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, test } from 'vitest';
import isError from '../../src/utils/is-error';

test('isError - should return true for an Error object', () => {
const error = new Error('Test error');
const result = isError(error);
expect(result).toBe(true);
});

test('isError - should return false for other types of values', () => {
expect(isError('')).toBe(false);
expect(isError(123)).toBe(false);
expect(isError({})).toBe(false);
expect(isError([])).toBe(false);
expect(isError(null)).toBe(false);
expect(isError(undefined)).toBe(false);
});
8 changes: 7 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ export default defineConfig({
coverage: {
provider: 'istanbul',
include: ['src'],
exclude: ['src/**/*.type.ts'],
exclude: [
'src/**/*.type.ts',
'src/locale/*',
'src/pipeline/*',
'src/utils/notify.ts',
'src/utils/typography.ts',
],
},
},
});

0 comments on commit fc19626

Please sign in to comment.