Skip to content

Commit

Permalink
refactor: array schema tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ariskemper committed Jan 16, 2024
1 parent 3a597a7 commit 4a4ac5a
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions library/src/schemas/array/array.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,42 @@ import { string } from '../string/index.ts';
import { array } from './array.ts';

describe('array', () => {
test('should pass only arrays', () => {
const schema1 = array(number());
const input1 = [1, 2, 3];
const output1 = parse(schema1, input1);
expect(output1).toEqual(input1);
const schema1 = array(number());
const schema2 = array(schema1);

const input1 = [1, 2, 3];
describe('should pass', () => {
test('number array should pass', () => {
const output1 = parse(schema1, input1);
expect(output1).toEqual(input1);
});

const schema2 = array(schema1);
const input2 = [input1, input1, input1];
const output2 = parse(schema2, input2);
expect(output2).toEqual(input2);
test('should pass nested arrays of numbers', () => {
const schema2 = array(schema1);
const input2 = [input1, input1, input1];
const output2 = parse(schema2, input2);
expect(output2).toEqual(input2);
});

const input3: number[] = [];
const output3 = parse(schema2, input3);
expect(output3).toEqual(input3);
test('should pass empty array', () => {
const input3: number[] = [];
const output3 = parse(schema2, input3);
expect(output3).toEqual(input3);
});
});

describe('should reject', () => {
test('if input is empty object', () => {
expect(() => parse(schema1, {})).toThrowError();
});

expect(() => parse(schema1, {})).toThrowError();
expect(() => parse(schema1, 123)).toThrowError();
expect(() => parse(schema2, input1)).toThrowError();
test('if empty object', () => {
expect(() => parse(schema1, {})).toThrowError();
});

test("if input doesn' match schema", () => {
expect(() => parse(schema2, input1)).toThrowError();
});
});

test('should throw custom error', () => {
Expand Down

0 comments on commit 4a4ac5a

Please sign in to comment.