Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

:pencil: - chore

## 1.4.1
- :beetle: fixed huge declaration file

## 1.4.0
- :rocket: dropped chai dependency in favor of own `expect` implementation

Expand Down
1 change: 0 additions & 1 deletion index.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion index.js

This file was deleted.

21 changes: 11 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@qavajs/validation",
"version": "1.4.0",
"version": "1.4.1",
"description": "Lib that transform plain english definition to validation functions",
"main": "index.js",
"main": "./lib/index.js",
"scripts": {
"build": "tsc",
"test": "vitest --coverage run"
Expand All @@ -20,14 +20,14 @@
"Alexandr Legchilov"
],
"license": "MIT",
"types": "./index.d.ts",
"types": "./lib/index.d.ts",
"bugs": {
"url": "https://github.com/qavajs/validation/issues"
},
"homepage": "https://github.com/qavajs/validation#readme",
"devDependencies": {
"@types/node": "^24.6.0",
"typescript": "^5.9.2",
"@types/node": "^24.6.2",
"typescript": "^5.9.3",
"@vitest/coverage-v8": "^3.2.4",
"vitest": "^3.2.4"
},
Expand Down
4 changes: 2 additions & 2 deletions src/expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class SoftAssertionError extends AssertionError {
name: string = 'SoftAssertionError';
}

type MatcherContext<Target> = {
export type MatcherContext<Target> = {
received: Target;
isNot: boolean;
isSoft: boolean;
Expand All @@ -17,7 +17,7 @@ type MatcherContext<Target> = {
asString(value: any): string;
};

type MatcherResult = {
export type MatcherResult = {
pass: boolean;
message: string;
};
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { getValidation, getPollValidation, verify, validationRegexp, poll, expect } from './verify';
export { AssertionError, SoftAssertionError } from './expect';
34 changes: 32 additions & 2 deletions src/matchers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
import { expect as base } from './expect';
import { expect as base, type MatcherResult, type MatcherContext } from './expect';
import Ajv from 'ajv';

export const expect = base.extend({
export type BaseMatchers = {
toSimpleEqual(this: MatcherContext<any>, expected: any): MatcherResult;
toEqual(this: MatcherContext<any>, expected: any): MatcherResult;
toCaseInsensitiveEqual(this: MatcherContext<any>, expected: string): MatcherResult;
toBe(this: MatcherContext<any>, expected: any): MatcherResult;
toBeGreaterThan(this: MatcherContext<any>, expected: number): MatcherResult;
toBeGreaterThanOrEqual(this: MatcherContext<any>, expected: number): MatcherResult;
toBeLessThan(this: MatcherContext<any>, expected: number): MatcherResult;
toBeLessThanOrEqual(this: MatcherContext<any>, expected: number): MatcherResult;
toBeNaN(this: MatcherContext<any>): MatcherResult;
toBeNull(this: MatcherContext<any>): MatcherResult;
toBeUndefined(this: MatcherContext<any>): MatcherResult;
toBeTruthy(this: MatcherContext<any>): MatcherResult;
toContain(this: MatcherContext<any>, expected: any): MatcherResult;
toDeepEqual(this: MatcherContext<any>, expected: any): MatcherResult;
toStrictEqual(this: MatcherContext<any>, expected: any): MatcherResult;
toHaveLength(this: MatcherContext<any>, expected: number): MatcherResult;
toHaveProperty(this: MatcherContext<any>, key: string, value?: any): MatcherResult;
toMatch(this: MatcherContext<any>, expected: string | RegExp): MatcherResult;
toThrow(this: MatcherContext<() => any>, expected?: string | RegExp): MatcherResult;
toSatisfy(this: MatcherContext<any>, expected: (received: any) => boolean): MatcherResult;
toResolveWith(this: MatcherContext<Promise<any>>, expected: any): Promise<MatcherResult>;
toRejectWith(this: MatcherContext<Promise<any>>, expected: string): Promise<MatcherResult>;
toPass(this: MatcherContext<() => any>): Promise<MatcherResult>;
toMatchSchema(this: MatcherContext<any>, schema: object): MatcherResult;
toHaveMembers(this: MatcherContext<any[]>, expected: any[]): MatcherResult;
toIncludeMembers(this: MatcherContext<any[]>, expected: any[]): MatcherResult;
toHaveType(this: MatcherContext<any>, expected: string): MatcherResult;
}

export const expect = base.extend<BaseMatchers>({
toSimpleEqual(expected: any) {
const pass = this.received == expected;
const message = this.formatMessage(this.received, expected, 'to equal', this.isNot);
Expand Down
2 changes: 1 addition & 1 deletion test/expect.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from '../src/matchers';
import { expect } from '../src';
import { test, describe, expect as vitestExpect } from 'vitest';

describe('Basic assertions', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/poll.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from 'vitest';
import { getPollValidation, poll } from '../src/verify';
import { getPollValidation, poll } from '../src';

function asyncActualValueString() {
let index = 0;
Expand Down
3 changes: 1 addition & 2 deletions test/validationTransformer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { test, expect } from 'vitest';
import { getValidation } from '../src/verify';
import { AssertionError, SoftAssertionError } from '../src/expect';
import { getValidation, AssertionError, SoftAssertionError } from '../src';

type TestParams = {
testName: string;
Expand Down