Skip to content
Vitest 3
Main Navigation 가이드 & API구성브라우저 모드고급 API
3.2.0
2.1.9
1.6.1
0.34.6

한국어

English
简体中文
繁體中文
Español
Français
Русский
Português – Brasil
Deutsch
日本語
Italiano
Polski
Türkçe
čeština
magyar

한국어

English
简体中文
繁體中文
Español
Français
Русский
Português – Brasil
Deutsch
日本語
Italiano
Polski
Türkçe
čeština
magyar

외관

Sidebar Navigation

소개

Vitest를 선택하는 이유

시작하기

기능

Vitest 구성하기

API

테스트 API 참조

Mock 함수

Vi

expect

expectTypeOf

assert

assertType

가이드

명령줄 인터페이스

테스트 필터링

테스트 프로젝트

리포터

커버리지

스냅샷

모킹

병렬 처리

타입 검사

Vitest UI

소스 내 테스팅

테스트 컨텍스트

테스트 어노테이션

테스트 환경

매처 확장하기

IDE 통합

디버깅

일반적인 오류

마이그레이션 가이드

Vitest 3.0으로 마이그레이션

Jest에서 마이그레이션

성능

테스트 성능 프로파일링

성능 향상

브라우저 모드

고급 API

다른 테스트 러너와의 비교

이 페이지에서

assert ​

Vitest는 불변성을 확인하기 위해 chai에서 assert 메서드를 다시 내보냅니다.

assert ​

  • 타입: (expression: any, message?: string) => asserts expression

주어진 expression이 참(truthy)인지 단언합니다. 그렇지 않으면 단언이 실패합니다.

ts
import { assert, test } from 'vitest';

test('assert', () => {
  assert('foo' !== 'bar', 'foo는 bar와 같지 않아야 합니다');
});

fail ​

  • 타입:
    • (message?: string) => never
    • <T>(actual: T, expected: T, message?: string, operator?: string) => never

강제로 단언 실패를 발생시킵니다.

ts
import { assert, test } from 'vitest';

test('assert.fail', () => {
  assert.fail('실패 시 오류 메시지');
  assert.fail('foo', 'bar', 'foo는 bar가 아닙니다', '===');
});

isOk ​

  • 타입: <T>(value: T, message?: string) => void
  • 별칭 ok

주어진 value가 참(truthy)인지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.isOk', () => {
  assert.isOk('foo', '모든 참 값은 ok입니다');
  assert.isOk(false, 'false는 참이 아니므로 실패합니다');
});

isNotOk ​

  • 타입: <T>(value: T, message?: string) => void
  • 별칭 notOk

주어진 value가 거짓(falsy)인지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.isNotOk', () => {
  assert.isNotOk('foo', '이것은 실패합니다. 참 값은 ok가 아닙니다');
  assert.isNotOk(false, 'false는 거짓이므로 통과합니다');
});

equal ​

  • 타입: <T>(actual: T, expected: T, message?: string) => void

actual과 expected의 비엄격 동등성(==)을 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.equal', () => {
  assert.equal(Math.sqrt(4), '2');
});

notEqual ​

  • 타입: <T>(actual: T, expected: T, message?: string) => void

actual과 expected의 비엄격 부등성(!=)을 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.notEqual', () => {
  assert.notEqual(Math.sqrt(4), 3);
});

strictEqual ​

  • 타입: <T>(actual: T, expected: T, message?: string) => void

actual과 expected의 엄격 동등성(===)을 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.strictEqual', () => {
  assert.strictEqual(Math.sqrt(4), 2);
});

deepEqual ​

  • 타입: <T>(actual: T, expected: T, message?: string) => void

actual이 expected와 깊이 동등한지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.deepEqual', () => {
  assert.deepEqual({ color: 'green' }, { color: 'green' });
});

notDeepEqual ​

  • 타입: <T>(actual: T, expected: T, message?: string) => void

actual이 expected와 깊이 동등하지 않은지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.notDeepEqual', () => {
  assert.notDeepEqual({ color: 'green' }, { color: 'red' });
});

isAbove ​

  • 타입: (valueToCheck: number, valueToBeAbove: number, message?: string) => void

valueToCheck가 valueToBeAbove보다 엄격하게 큰지(>) 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.isAbove', () => {
  assert.isAbove(5, 2, '5는 2보다 엄격하게 큽니다');
});

isAtLeast ​

  • 타입: (valueToCheck: number, valueToBeAtLeast: number, message?: string) => void

valueToCheck가 valueToBeAtLeast보다 크거나 같은지(>=) 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.isAtLeast', () => {
  assert.isAtLeast(5, 2, '5는 2보다 크거나 같습니다');
  assert.isAtLeast(3, 3, '3은 3보다 크거나 같습니다');
});

isBelow ​

  • 타입: (valueToCheck: number, valueToBeBelow: number, message?: string) => void

valueToCheck가 valueToBeBelow보다 엄격하게 작은지(<) 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.isBelow', () => {
  assert.isBelow(3, 6, '3은 6보다 엄격하게 작습니다');
});

isAtMost ​

  • 타입: (valueToCheck: number, valueToBeAtMost: number, message?: string) => void

valueToCheck가 valueToBeAtMost보다 작거나 같은지(<=) 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.isAtMost', () => {
  assert.isAtMost(3, 6, '3은 6보다 작거나 같습니다');
  assert.isAtMost(4, 4, '4는 4보다 작거나 같습니다');
});

isTrue ​

  • 타입: <T>(value: T, message?: string) => void

value가 true인지 단언합니다.

ts
import { assert, test } from 'vitest';

const testPassed = true;

test('assert.isTrue', () => {
  assert.isTrue(testPassed);
});

isNotTrue ​

  • 타입: <T>(value: T, message?: string) => void

value가 true가 아닌지 단언합니다.

ts
import { assert, test } from 'vitest';

const testPassed = 'ok';

test('assert.isNotTrue', () => {
  assert.isNotTrue(testPassed);
});

isFalse ​

  • 타입: <T>(value: T, message?: string) => void

value가 false인지 단언합니다.

ts
import { assert, test } from 'vitest';

const testPassed = false;

test('assert.isFalse', () => {
  assert.isFalse(testPassed);
});

isNotFalse ​

  • 타입: <T>(value: T, message?: string) => void

value가 false가 아닌지 단언합니다.

ts
import { assert, test } from 'vitest';

const testPassed = 'no';

test('assert.isNotFalse', () => {
  assert.isNotFalse(testPassed);
});

isNull ​

  • 타입: <T>(value: T, message?: string) => void

value가 null인지 단언합니다.

ts
import { assert, test } from 'vitest';

const error = null;

test('assert.isNull', () => {
  assert.isNull(error, 'error는 null입니다');
});

isNotNull ​

  • 타입: <T>(value: T, message?: string) => void

value가 null이 아닌지 단언합니다.

ts
import { assert, test } from 'vitest';

const error = { message: '오류가 발생했습니다' };

test('assert.isNotNull', () => {
  assert.isNotNull(error, 'error는 null이 아니라 객체입니다');
});

isNaN ​

  • 타입: <T>(value: T, message?: string) => void

value가 NaN인지 단언합니다.

ts
import { assert, test } from 'vitest';

const calculation = 1 * 'vitest';

test('assert.isNaN', () => {
  assert.isNaN(calculation, '1 * "vitest"는 NaN입니다');
});

isNotNaN ​

  • 타입: <T>(value: T, message?: string) => void

value가 NaN이 아닌지 단언합니다.

ts
import { assert, test } from 'vitest';

const calculation = 1 * 2;

test('assert.isNotNaN', () => {
  assert.isNotNaN(calculation, '1 * 2는 NaN이 아니라 2입니다');
});

exists ​

  • 타입: <T>(value: T, message?: string) => void

value가 null도 undefined도 아닌지 단언합니다.

ts
import { assert, test } from 'vitest';

const name = 'foo';

test('assert.exists', () => {
  assert.exists(name, 'foo는 null도 undefined도 아닙니다');
});

notExists ​

  • 타입: <T>(value: T, message?: string) => void

value가 null이거나 undefined인지 단언합니다.

ts
import { assert, test } from 'vitest';

const foo = null;
const bar = undefined;

test('assert.notExists', () => {
  assert.notExists(foo, 'foo는 null이므로 존재하지 않습니다');
  assert.notExists(bar, 'bar는 undefined이므로 존재하지 않습니다');
});

isUndefined ​

  • 타입: <T>(value: T, message?: string) => void

value가 undefined인지 단언합니다.

ts
import { assert, test } from 'vitest';

const name = undefined;

test('assert.isUndefined', () => {
  assert.isUndefined(name, 'name은 undefined입니다');
});

isDefined ​

  • 타입: <T>(value: T, message?: string) => void

value가 undefined가 아닌지 단언합니다.

ts
import { assert, test } from 'vitest';

const name = 'foo';

test('assert.isDefined', () => {
  assert.isDefined(name, 'name은 정의되어 있습니다');
});

isFunction ​

  • 타입: <T>(value: T, message?: string) => void
  • 별칭: isCallablevalue가 함수인지 단언합니다.
ts
import { assert, test } from 'vitest';

function name() {
  return 'foo';
}

test('assert.isFunction', () => {
  assert.isFunction(name, 'name은 함수입니다');
});

isNotFunction ​

  • 타입: <T>(value: T, message?: string) => void
  • 별칭: isNotCallable

value가 함수가 아닌지 단언합니다.

ts
import { assert, test } from 'vitest';

const name = 'foo';

test('assert.isNotFunction', () => {
  assert.isNotFunction(name, 'name은 함수가 아니라 문자열입니다');
});

isObject ​

  • 타입: <T>(value: T, message?: string) => void

value가 Object 타입의 객체인지 단언합니다(Object.prototype.toString에 의해 밝혀진 대로). 이 단언은 서브클래스 객체와 일치하지 않습니다.

ts
import { assert, test } from 'vitest';

const someThing = { color: 'red', shape: 'circle' };

test('assert.isObject', () => {
  assert.isObject(someThing, 'someThing은 객체입니다');
});

isNotObject ​

  • 타입: <T>(value: T, message?: string) => void

value가 Object 타입의 객체가 아닌지 단언합니다(Object.prototype.toString에 의해 밝혀진 대로). 이 단언은 서브클래스 객체와 일치하지 않습니다.

ts
import { assert, test } from 'vitest';

const someThing = 'redCircle';

test('assert.isNotObject', () => {
  assert.isNotObject(someThing, 'someThing은 객체가 아니라 문자열입니다');
});

isArray ​

  • 타입: <T>(value: T, message?: string) => void

value가 배열인지 단언합니다.

ts
import { assert, test } from 'vitest';

const color = ['red', 'green', 'yellow'];

test('assert.isArray', () => {
  assert.isArray(color, 'color는 배열입니다');
});

isNotArray ​

  • 타입: <T>(value: T, message?: string) => void

value가 배열이 아닌지 단언합니다.

ts
import { assert, test } from 'vitest';

const color = 'red';

test('assert.isNotArray', () => {
  assert.isNotArray(color, 'color는 배열이 아니라 문자열입니다');
});

isString ​

  • 타입: <T>(value: T, message?: string) => void

value가 문자열인지 단언합니다.

ts
import { assert, test } from 'vitest';

const color = 'red';

test('assert.isString', () => {
  assert.isString(color, 'color는 문자열입니다');
});

isNotString ​

  • 타입: <T>(value: T, message?: string) => void

value가 문자열이 아닌지 단언합니다.

ts
import { assert, test } from 'vitest';

const color = ['red', 'green', 'yellow'];

test('assert.isNotString', () => {
  assert.isNotString(color, 'color는 문자열이 아니라 배열입니다');
});

isNumber ​

  • 타입: <T>(value: T, message?: string) => void

value가 숫자인지 단언합니다.

ts
import { assert, test } from 'vitest';

const colors = 3;

test('assert.isNumber', () => {
  assert.isNumber(colors, 'colors는 숫자입니다');
});

isNotNumber ​

  • 타입: <T>(value: T, message?: string) => void

value가 숫자가 아닌지 단언합니다.

ts
import { assert, test } from 'vitest';

const colors = '3 colors';

test('assert.isNotNumber', () => {
  assert.isNotNumber(colors, 'colors는 숫자가 아니라 문자열입니다');
});

isFinite ​

  • 타입: <T>(value: T, message?: string) => void

value가 유한한 숫자인지(NaN, Infinity가 아닌) 단언합니다.

ts
import { assert, test } from 'vitest';

const colors = 3;

test('assert.isFinite', () => {
  assert.isFinite(colors, 'colors는 NaN 또는 Infinity가 아닌 숫자입니다');
});

isBoolean ​

  • 타입: <T>(value: T, message?: string) => void

value가 불리언인지 단언합니다.

ts
import { assert, test } from 'vitest';

const isReady = true;

test('assert.isBoolean', () => {
  assert.isBoolean(isReady, 'isReady는 불리언입니다');
});

isNotBoolean ​

  • 타입: <T>(value: T, message?: string) => void

value가 불리언이 아닌지 단언합니다.

ts
import { assert, test } from 'vitest';

const isReady = 'sure';

test('assert.isNotBoolean', () => {
  assert.isNotBoolean(isReady, 'isReady는 불리언이 아니라 문자열입니다');
});

typeOf ​

  • 타입: <T>(value: T, name: string, message?: string) => void

Object.prototype.toString에 의해 결정된 value의 타입이 name인지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.typeOf', () => {
  assert.typeOf({ color: 'red' }, 'object', '우리는 객체를 가지고 있습니다');
  assert.typeOf(['red', 'green'], 'array', '우리는 배열을 가지고 있습니다');
  assert.typeOf('red', 'string', '우리는 문자열을 가지고 있습니다');
  assert.typeOf(/red/, 'regexp', '우리는 정규 표현식을 가지고 있습니다');
  assert.typeOf(null, 'null', '우리는 null을 가지고 있습니다');
  assert.typeOf(undefined, 'undefined', '우리는 undefined를 가지고 있습니다');
});

notTypeOf ​

  • 타입: <T>(value: T, name: string, message?: string) => void

Object.prototype.toString에 의해 결정된 value의 타입이 name이 아닌지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.notTypeOf', () => {
  assert.notTypeOf('red', 'number', '"red"는 숫자가 아닙니다');
});

instanceOf ​

  • 타입: <T>(value: T, constructor: Function, message?: string) => void

value가 constructor의 인스턴스인지 단언합니다.

ts
import { assert, test } from 'vitest';

function Person(name) {
  this.name = name;
}
const foo = new Person('foo');

class Tea {
  constructor(name) {
    this.name = name;
  }
}
const coffee = new Tea('coffee');

test('assert.instanceOf', () => {
  assert.instanceOf(foo, Person, 'foo는 Person의 인스턴스입니다');
  assert.instanceOf(coffee, Tea, 'coffee는 Tea의 인스턴스입니다');
});

notInstanceOf ​

  • 타입: <T>(value: T, constructor: Function, message?: string) => void

value가 constructor의 인스턴스가 아닌지 단언합니다.

ts
import { assert, test } from 'vitest';

function Person(name) {
  this.name = name;
}
const foo = new Person('foo');

class Tea {
  constructor(name) {
    this.name = name;
  }
}
const coffee = new Tea('coffee');

test('assert.notInstanceOf', () => {
  assert.notInstanceOf(foo, Tea, 'foo는 Tea의 인스턴스가 아닙니다');
});

include ​

  • 타입:
    • (haystack: string, needle: string, message?: string) => void
    • <T>(haystack: readonly T[] | ReadonlySet<T> | ReadonlyMap<any, T>, needle: T, message?: string) => void
    • <T extends object>(haystack: WeakSet<T>, needle: T, message?: string) => void
    • <T>(haystack: T, needle: Partial<T>, message?: string) => void

haystack이 needle을 포함하는지 단언합니다. 배열에 값이 포함되어 있는지, 문자열에 부분 문자열이 포함되어 있는지, 객체에 속성 하위 집합이 포함되어 있는지 단언하는 데 사용할 수 있습니다.

ts
import { assert, test } from 'vitest';

test('assert.include', () => {
  assert.include([1, 2, 3], 2, '배열에 값이 포함되어 있습니다');
  assert.include('foobar', 'foo', '문자열에 부분 문자열이 포함되어 있습니다');
  assert.include(
    { foo: 'bar', hello: 'universe' },
    { foo: 'bar' },
    '객체에 속성이 포함되어 있습니다'
  );
});

notInclude ​

  • 타입:
    • (haystack: string, needle: string, message?: string) => void
    • <T>(haystack: readonly T[] | ReadonlySet<T> | ReadonlyMap<any, T>, needle: T, message?: string) => void
    • <T extends object>(haystack: WeakSet<T>, needle: T, message?: string) => void
    • <T>(haystack: T, needle: Partial<T>, message?: string) => void

haystack이 needle을 포함하지 않는지 단언합니다. 배열에 값이 없는지, 문자열에 부분 문자열이 없는지, 객체에 속성 하위 집합이 없는지 단언하는 데 사용할 수 있습니다.

ts
import { assert, test } from 'vitest';

test('assert.notInclude', () => {
  assert.notInclude([1, 2, 3], 4, "배열에 4가 포함되어 있지 않습니다");
  assert.notInclude('foobar', 'baz', "foobar에 baz가 포함되어 있지 않습니다");
  assert.notInclude(
    { foo: 'bar', hello: 'universe' },
    { foo: 'baz' },
    "객체에 속성이 포함되어 있지 않습니다"
  );
});

deepInclude ​

  • 타입:
  • (haystack: string, needle: string, message?: string) => void
  • <T>(haystack: readonly T[] | ReadonlySet<T> | ReadonlyMap<any, T>, needle: T, message?: string) => void
  • <T>(haystack: T, needle: T extends WeakSet<any> ? never : Partial<T>, message?: string) => void

haystack이 needle을 포함하는지 단언합니다. 배열에 값이 포함되어 있는지 또는 객체에 속성 하위 집합이 포함되어 있는지 단언하는 데 사용할 수 있습니다. 깊은 동등성이 사용됩니다.

ts
import { assert, test } from 'vitest';

const obj1 = { a: 1 };
const obj2 = { b: 2 };

test('assert.deepInclude', () => {
  assert.deepInclude([obj1, obj2], { a: 1 });
  assert.deepInclude({ foo: obj1, bar: obj2 }, { foo: { a: 1 } });
});

notDeepInclude ​

  • 타입:
    • (haystack: string, needle: string, message?: string) => void
    • <T>(haystack: readonly T[] | ReadonlySet<T> | ReadonlyMap<any, T>, needle: T, message?: string) => void
    • <T>(haystack: T, needle: T extends WeakSet<any> ? never : Partial<T>, message?: string) => void

haystack이 needle을 포함하지 않는지 단언합니다. 배열에 값이 없는지 또는 객체에 속성 하위 집합이 없는지 단언하는 데 사용할 수 있습니다. 깊은 동등성이 사용됩니다.

ts
import { assert, test } from 'vitest';

const obj1 = { a: 1 };
const obj2 = { b: 2 };

test('assert.notDeepInclude', () => {
  assert.notDeepInclude([obj1, obj2], { a: 10 });
  assert.notDeepInclude({ foo: obj1, bar: obj2 }, { foo: { a: 10 } });
});

nestedInclude ​

  • 타입: (haystack: any, needle: any, message?: string) => void

haystack이 needle을 포함하는지 단언합니다. 객체에 속성 하위 집합이 포함되어 있는지 단언하는 데 사용할 수 있습니다. 중첩된 속성을 참조하기 위해 점(.) 및 대괄호([]) 표기법을 사용할 수 있습니다. 속성 이름의 '[]' 및 '.'는 이중 백슬래시를 사용하여 이스케이프할 수 있습니다.

ts
import { assert, test } from 'vitest';

test('assert.nestedInclude', () => {
  assert.nestedInclude({ '.a': { b: 'x' } }, { '\\.a.[b]': 'x' });
  assert.nestedInclude({ a: { '[b]': 'x' } }, { 'a.\\[b\\]': 'x' });
});

notNestedInclude ​

  • 타입: (haystack: any, needle: any, message?: string) => void

haystack이 needle을 포함하지 않는지 단언합니다. 객체에 속성 하위 집합이 포함되어 있지 않은지 단언하는 데 사용할 수 있습니다. 중첩된 속성을 참조하기 위해 점(.) 및 대괄호([]) 표기법을 사용할 수 있습니다. 속성 이름의 '[]' 및 '.'는 이중 백슬래시를 사용하여 이스케이프할 수 있습니다.

ts
import { assert, test } from 'vitest';

test('assert.notNestedInclude', () => {
  assert.notNestedInclude({ '.a': { b: 'x' } }, { '\\.a.b': 'y' });
  assert.notNestedInclude({ a: { '[b]': 'x' } }, { 'a.\\[b\\]': 'y' });
});

deepNestedInclude ​

  • 타입: (haystack: any, needle: any, message?: string) => void

haystack이 needle을 포함하는지 단언합니다. 객체에 속성 하위 집합이 포함되어 있는지 단언하는 데 사용할 수 있으며, 깊은 동등성을 확인합니다. 중첩된 속성을 참조하기 위해 점(.) 및 대괄호([]) 표기법을 사용할 수 있습니다. 속성 이름의 '[]' 및 '.'는 이중 백슬래시를 사용하여 이스케이프할 수 있습니다.

ts
import { assert, test } from 'vitest';

test('assert.deepNestedInclude', () => {
  assert.deepNestedInclude({ a: { b: [{ x: 1 }] } }, { 'a.b[0]': { x: 1 } });
  assert.deepNestedInclude(
    { '.a': { '[b]': { x: 1 } } },
    { '\\.a.\\[b\\]': { x: 1 } }
  );
});

notDeepNestedInclude ​

  • 타입: (haystack: any, needle: any, message?: string) => void

haystack이 needle을 포함하지 않는지 단언합니다. 객체에 속성 하위 집합이 없는지 단언하는 데 사용할 수 있으며, 깊은 동등성을 확인합니다. 중첩된 속성을 참조하기 위해 점(.) 및 대괄호([]) 표기법을 사용할 수 있습니다. 속성 이름의 '[]' 및 '.'는 이중 백슬래시를 사용하여 이스케이프할 수 있습니다.

ts
import { assert, test } from 'vitest';

test('assert.notDeepNestedInclude', () => {
  assert.notDeepNestedInclude({ a: { b: [{ x: 1 }] } }, { 'a.b[0]': { y: 1 } });
  assert.notDeepNestedInclude(
    { '.a': { '[b]': { x: 1 } } },
    { '\\.a.\\[b\\]': { y: 2 } }
  );
});

ownInclude ​

  • 타입: (haystack: any, needle: any, message?: string) => void

haystack이 needle을 포함하는지 단언합니다. 상속된 속성을 무시하면서 객체에 속성 하위 집합이 포함되어 있는지 단언하는 데 사용할 수 있습니다.

ts
import { assert, test } from 'vitest';

test('assert.ownInclude', () => {
  assert.ownInclude({ a: 1 }, { a: 1 });
});

notOwnInclude ​

  • 타입: (haystack: any, needle: any, message?: string) => void

haystack이 needle을 포함하지 않는지 단언합니다. 상속된 속성을 무시하면서 객체에 속성 하위 집합이 없는지 단언하는 데 사용할 수 있습니다.

ts
import { assert, test } from 'vitest';

const obj1 = {
  b: 2,
};

const obj2 = Object.create(obj1);
obj2.a = 1;

test('assert.notOwnInclude', () => {
  assert.notOwnInclude(obj2, { b: 2 });
});

deepOwnInclude ​

  • 타입: (haystack: any, needle: any, message?: string) => void

haystack이 needle을 포함하는지 단언합니다. 상속된 속성을 무시하고 깊은 동등성을 확인하면서 객체에 속성 하위 집합이 포함되어 있는지 단언하는 데 사용할 수 있습니다.

ts
import { assert, test } from 'vitest';

test('assert.deepOwnInclude', () => {
  assert.deepOwnInclude({ a: { b: 2 } }, { a: { b: 2 } });
});

notDeepOwnInclude ​

  • 타입: (haystack: any, needle: any, message?: string) => void

haystack이 needle을 포함하지 않는지 단언합니다. 상속된 속성을 무시하고 깊은 동등성을 확인하면서 객체에 속성 하위 집합이 없는지 단언하는 데 사용할 수 있습니다.

ts
import { assert, test } from 'vitest';

test('assert.notDeepOwnInclude', () => {
  assert.notDeepOwnInclude({ a: { b: 2 } }, { a: { c: 3 } });
});

match ​

  • 타입: (value: string, regexp: RegExp, message?: string) => void

value가 정규 표현식 regexp와 일치하는지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.match', () => {
  assert.match('foobar', /^foo/, '정규 표현식이 일치합니다');
});

notMatch ​

  • 타입: (value: string, regexp: RegExp, message?: string) => void

value가 정규 표현식 regexp와 일치하지 않는지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.notMatch', () => {
  assert.notMatch('foobar', /^foo/, '정규 표현식이 일치하지 않습니다');
});

property ​

  • 타입: <T>(object: T, property: string, message?: string) => void

object에 property라는 이름의 직접 또는 상속된 속성이 있는지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.property', () => {
  assert.property({ tea: { green: 'matcha' } }, 'tea');
  assert.property({ tea: { green: 'matcha' } }, 'toString');
});

notProperty ​

  • 타입: <T>(object: T, property: string, message?: string) => void

object에 property라는 이름의 직접 또는 상속된 속성이 없는지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.notProperty', () => {
  assert.notProperty({ tea: { green: 'matcha' } }, 'coffee');
});

propertyVal ​

  • 타입: <T, V>(object: T, property: string, value: V, message?: string) => void

object에 property라는 이름의 직접 또는 상속된 속성이 value로 주어진 값을 가지는지 단언합니다. 엄격한 동등성 검사(===)를 사용합니다.

ts
import { assert, test } from 'vitest';

test('assert.propertyVal', () => {
  assert.propertyVal({ tea: 'is good' }, 'tea', 'is good');
});

notPropertyVal ​

  • 타입: <T, V>(object: T, property: string, value: V, message?: string) => void

object에 property라는 이름의 직접 또는 상속된 속성이 value로 주어진 값을 가지지 않는지 단언합니다. 엄격한 동등성 검사(===)를 사용합니다.

ts
import { assert, test } from 'vitest';

test('assert.notPropertyVal', () => {
  assert.notPropertyVal({ tea: 'is good' }, 'tea', 'is bad');
  assert.notPropertyVal({ tea: 'is good' }, 'coffee', 'is good');
});

deepPropertyVal ​

  • 타입: <T, V>(object: T, property: string, value: V, message?: string) => void

object에 property라는 이름의 직접 또는 상속된 속성이 value로 주어진 값을 가지는지 단언합니다. 깊은 동등성 검사를 사용합니다.

ts
import { assert, test } from 'vitest';

test('assert.deepPropertyVal', () => {
  assert.deepPropertyVal({ tea: { green: 'matcha' } }, 'tea', {
    green: 'matcha',
  });
});

notDeepPropertyVal ​

  • 타입: <T, V>(object: T, property: string, value: V, message?: string) => void

object에 property라는 이름의 직접 또는 상속된 속성이 value로 주어진 값을 가지지 않는지 단언합니다. 깊은 동등성 검사를 사용합니다.

ts
import { assert, test } from 'vitest';

test('assert.notDeepPropertyVal', () => {
  assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'tea', {
    black: 'matcha',
  });
  assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'tea', {
    green: 'oolong',
  });
  assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'coffee', {
    green: 'matcha',
  });
});

nestedProperty ​

  • 타입: <T>(object: T, property: string, message?: string) => void

object에 property라는 이름의 직접 또는 상속된 속성이 있는지 단언합니다. property는 중첩된 참조를 위해 점(.) 및 대괄호([]) 표기법을 사용하는 문자열일 수 있습니다.

ts
import { assert, test } from 'vitest';

test('assert.nestedProperty', () => {
  assert.nestedProperty({ tea: { green: 'matcha' } }, 'tea.green');
});

notNestedProperty ​

  • 타입: <T>(object: T, property: string, message?: string) => void

object에 property라는 이름의 직접 또는 상속된 속성이 없는지 단언합니다. property는 중첩된 참조를 위해 점(.) 및 대괄호([]) 표기법을 사용하는 문자열일 수 있습니다.

ts
import { assert, test } from 'vitest';

test('assert.notNestedProperty', () => {
  assert.notNestedProperty({ tea: { green: 'matcha' } }, 'tea.oolong');
});

nestedPropertyVal ​

  • 타입: <T>(object: T, property: string, value: any, message?: string) => void

object에 property라는 이름의 속성이 value로 주어진 값을 가지는지 단언합니다. property는 중첩된 참조를 위해 점(.) 및 대괄호([]) 표기법을 사용할 수 있습니다. 엄격한 동등성 검사(===)를 사용합니다.

ts
import { assert, test } from 'vitest';

test('assert.nestedPropertyVal', () => {
  assert.nestedPropertyVal({ tea: { green: 'matcha' } }, 'tea.green', 'matcha');
});

notNestedPropertyVal ​

  • 타입: <T>(object: T, property: string, value: any, message?: string) => void

object에 property라는 이름의 속성이 value로 주어진 값을 가지지 않는지 단언합니다. property는 중첩된 참조를 위해 점(.) 및 대괄호([]) 표기법을 사용할 수 있습니다. 엄격한 동등성 검사(===)를 사용합니다.

ts
import { assert, test } from 'vitest';

test('assert.notNestedPropertyVal', () => {
  assert.notNestedPropertyVal(
    { tea: { green: 'matcha' } },
    'tea.green',
    'konacha'
  );
  assert.notNestedPropertyVal(
    { tea: { green: 'matcha' } },
    'coffee.green',
    'matcha'
  );
});

deepNestedPropertyVal ​

  • 타입: <T>(object: T, property: string, value: any, message?: string) => void

object에 property라는 이름의 속성이 value로 주어진 값을 가지는지 단언합니다. property는 중첩된 참조를 위해 점(.) 및 대괄호([]) 표기법을 사용할 수 있습니다. 깊은 동등성 검사를 사용합니다.

ts
import { assert, test } from 'vitest';

test('assert.deepNestedPropertyVal', () => {
  assert.deepNestedPropertyVal(
    { tea: { green: 'matcha' } },
    'tea.green',
    'konacha'
  );
  assert.deepNestedPropertyVal(
    { tea: { green: 'matcha' } },
    'coffee.green',
    'matcha'
  );
});

notDeepNestedPropertyVal ​

  • 타입: <T>(object: T, property: string, value: any, message?: string) => void

object에 property라는 이름의 속성이 value로 주어진 값을 가지지 않는지 단언합니다. property는 중첩된 참조를 위해 점(.) 및 대괄호([]) 표기법을 사용할 수 있습니다. 깊은 동등성 검사를 사용합니다.

ts
import { assert, test } from 'vitest';

test('assert.notDeepNestedPropertyVal', () => {
  assert.notDeepNestedPropertyVal(
    { tea: { green: { matcha: 'yum' } } },
    'tea.green',
    { oolong: 'yum' }
  );
  assert.notDeepNestedPropertyVal(
    { tea: { green: { matcha: 'yum' } } },
    'tea.green',
    { matcha: 'yuck' }
  );
  assert.notDeepNestedPropertyVal(
    { tea: { green: { matcha: 'yum' } } },
    'tea.black',
    { matcha: 'yum' }
  );
});

lengthOf ​

  • 타입: <T extends { readonly length?: number | undefined } | { readonly size?: number | undefined }>(object: T, length: number, message?: string) => void

object가 예상되는 값을 가진 length 또는 size를 가지는지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.lengthOf', () => {
  assert.lengthOf([1, 2, 3], 3, '배열의 길이는 3입니다');
  assert.lengthOf('foobar', 6, '문자열의 길이는 6입니다');
  assert.lengthOf(new Set([1, 2, 3]), 3, '세트의 크기는 3입니다');
  assert.lengthOf(
    new Map([
      ['a', 1],
      ['b', 2],
      ['c', 3],
    ]),
    3,
    '맵의 크기는 3입니다'
  );
});

hasAnyKeys ​

  • 타입: <T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string) => void

object가 제공된 keys 중 적어도 하나를 가지는지 단언합니다. 키 배열 대신 단일 객체를 제공할 수도 있으며, 해당 객체의 키가 예상되는 키 집합으로 사용됩니다.

ts
import { assert, test } from 'vitest';

test('assert.hasAnyKeys', () => {
  assert.hasAnyKeys({ foo: 1, bar: 2, baz: 3 }, ['foo', 'iDontExist', 'baz']);
  assert.hasAnyKeys(
    { foo: 1, bar: 2, baz: 3 },
    { foo: 30, iDontExist: 99, baz: 1337 }
  );
  assert.hasAnyKeys(
    new Map([
      [{ foo: 1 }, 'bar'],
      ['key', 'value'],
    ]),
    [{ foo: 1 }, 'key']
  );
  assert.hasAnyKeys(new Set([{ foo: 'bar' }, 'anotherKey']), [
    { foo: 'bar' },
    'anotherKey',
  ]);
});

hasAllKeys ​

  • 타입: <T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string) => void

object가 제공된 keys를 모두 가지고 있으며, 다른 키는 없는지 단언합니다. 키 배열 대신 단일 객체를 제공할 수도 있으며, 해당 객체의 키가 예상되는 키 집합으로 사용됩니다.

ts
import { assert, test } from 'vitest';

test('assert.hasAllKeys', () => {
  assert.hasAllKeys({ foo: 1, bar: 2, baz: 3 }, ['foo', 'bar', 'baz']);
  assert.hasAllKeys(
    { foo: 1, bar: 2, baz: 3 },
    { foo: 30, bar: 99, baz: 1337 }
  );
  assert.hasAllKeys(
    new Map([
      [{ foo: 1 }, 'bar'],
      ['key', 'value'],
    ]),
    [{ foo: 1 }, 'key']
  );
  assert.hasAllKeys(
    new Set([{ foo: 'bar' }, 'anotherKey'], [{ foo: 'bar' }, 'anotherKey'])
  );
});

containsAllKeys ​

  • 타입: <T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string) => void

object가 제공된 keys를 모두 가지고 있지만, 목록에 없는 다른 키를 가질 수도 있는지 단언합니다. 키 배열 대신 단일 객체를 제공할 수도 있으며, 해당 객체의 키가 예상되는 키 집합으로 사용됩니다.

ts
import { assert, test } from 'vitest';

test('assert.containsAllKeys', () => {
  assert.containsAllKeys({ foo: 1, bar: 2, baz: 3 }, ['foo', 'baz']);
  assert.containsAllKeys({ foo: 1, bar: 2, baz: 3 }, ['foo', 'bar', 'baz']);
  assert.containsAllKeys({ foo: 1, bar: 2, baz: 3 }, { foo: 30, baz: 1337 });
  assert.containsAllKeys(
    { foo: 1, bar: 2, baz: 3 },
    { foo: 30, bar: 99, baz: 1337 }
  );
  assert.containsAllKeys(
    new Map([
      [{ foo: 1 }, 'bar'],
      ['key', 'value'],
    ]),
    [{ foo: 1 }]
  );
  assert.containsAllKeys(
    new Map([
      [{ foo: 1 }, 'bar'],
      ['key', 'value'],
    ]),
    [{ foo: 1 }, 'key']
  );
  assert.containsAllKeys(
    new Set([{ foo: 'bar' }, 'anotherKey'], [{ foo: 'bar' }])
  );
  assert.containsAllKeys(
    new Set([{ foo: 'bar' }, 'anotherKey'], [{ foo: 'bar' }, 'anotherKey'])
  );
});

doesNotHaveAnyKeys ​

  • 타입: <T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string) => void

object가 제공된 keys 중 어느 것도 가지지 않는지 단언합니다. 키 배열 대신 단일 객체를 제공할 수도 있으며, 해당 객체의 키가 예상되는 키 집합으로 사용됩니다.

ts
import { assert, test } from 'vitest';

test('assert.doesNotHaveAnyKeys', () => {
  assert.doesNotHaveAnyKeys({ foo: 1, bar: 2, baz: 3 }, [
    'one',
    'two',
    'example',
  ]);
  assert.doesNotHaveAnyKeys(
    { foo: 1, bar: 2, baz: 3 },
    { one: 1, two: 2, example: 'foo' }
  );
  assert.doesNotHaveAnyKeys(
    new Map([
      [{ foo: 1 }, 'bar'],
      ['key', 'value'],
    ]),
    [{ one: 'two' }, 'example']
  );
  assert.doesNotHaveAnyKeys(
    new Set([{ foo: 'bar' }, 'anotherKey'], [{ one: 'two' }, 'example'])
  );
});

doesNotHaveAllKeys ​

  • 타입: <T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string) => void

object가 제공된 keys 중 적어도 하나를 가지지 않는지 단언합니다. 키 배열 대신 단일 객체를 제공할 수도 있으며, 해당 객체의 키가 예상되는 키 집합으로 사용됩니다.

ts
import { assert, test } from 'vitest';

test('assert.doesNotHaveAllKeys', () => {
  assert.doesNotHaveAllKeys({ foo: 1, bar: 2, baz: 3 }, [
    'one',
    'two',
    'example',
  ]);
  assert.doesNotHaveAllKeys(
    { foo: 1, bar: 2, baz: 3 },
    { one: 1, two: 2, example: 'foo' }
  );
  assert.doesNotHaveAllKeys(
    new Map([
      [{ foo: 1 }, 'bar'],
      ['key', 'value'],
    ]),
    [{ one: 'two' }, 'example']
  );
  assert.doesNotHaveAllKeys(new Set([{ foo: 'bar' }, 'anotherKey']), [
    { one: 'two' },
    'example',
  ]);
});

hasAnyDeepKeys ​

  • 타입: <T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string) => void

object가 제공된 keys 중 적어도 하나를 가지는지 단언합니다. Set과 Map은 객체를 키로 가질 수 있으므로 이 단언을 사용하여 깊은 비교를 수행할 수 있습니다. 키 배열 대신 단일 객체를 제공할 수도 있으며, 해당 객체의 키가 예상되는 키 집합으로 사용됩니다.

ts
import { assert, test } from 'vitest';

test('assert.hasAnyDeepKeys', () => {
  assert.hasAnyDeepKeys(
    new Map([
      [{ one: 'one' }, 'valueOne'],
      [1, 2],
    ]),
    { one: 'one' }
  );
  assert.hasAnyDeepKeys(
    new Map([
      [{ one: 'one' }, 'valueOne'],
      [1, 2],
    ]),
    [{ one: 'one' }, { two: 'two' }]
  );
  assert.hasAnyDeepKeys(
    new Map([
      [{ one: 'one' }, 'valueOne'],
      [{ two: 'two' }, 'valueTwo'],
    ]),
    [{ one: 'one' }, { two: 'two' }]
  );
  assert.hasAnyDeepKeys(new Set([{ one: 'one' }, { two: 'two' }]), {
    one: 'one',
  });
  assert.hasAnyDeepKeys(new Set([{ one: 'one' }, { two: 'two' }]), [
    { one: 'one' },
    { three: 'three' },
  ]);
  assert.hasAnyDeepKeys(new Set([{ one: 'one' }, { two: 'two' }]), [
    { one: 'one' },
    { two: 'two' },
  ]);
});

hasAllDeepKeys ​

  • 타입: <T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string) => void

object가 제공된 keys를 모두 가지고 있으며, 다른 키는 없는지 단언합니다. Set과 Map은 객체를 키로 가질 수 있으므로 이 단언을 사용하여 깊은 비교를 수행할 수 있습니다. 키 배열 대신 단일 객체를 제공할 수도 있으며, 해당 객체의 키가 예상되는 키 집합으로 사용됩니다.

ts
import { assert, test } from 'vitest';

test('assert.hasAllDeepKeys', () => {
  assert.hasAllDeepKeys(new Map([[{ one: 'one' }, 'valueOne']]), {
    one: 'one',
  });
  assert.hasAllDeepKeys(
    new Map([
      [{ one: 'one' }, 'valueOne'],
      [{ two: 'two' }, 'valueTwo'],
    ]),
    [{ one: 'one' }, { two: 'two' }]
  );
  assert.hasAllDeepKeys(new Set([{ one: 'one' }]), { one: 'one' });
  assert.hasAllDeepKeys(new Set([{ one: 'one' }, { two: 'two' }]), [
    { one: 'one' },
    { two: 'two' },
  ]);
});

containsAllDeepKeys ​

  • 타입: <T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string) => void

object가 제공된 keys를 모두 포함하는지 단언합니다. Set과 Map은 객체를 키로 가질 수 있으므로 이 단언을 사용하여 깊은 비교를 수행할 수 있습니다. 키 배열 대신 단일 객체를 제공할 수도 있으며, 해당 객체의 키가 예상되는 키 집합으로 사용됩니다.

ts
import { assert, test } from 'vitest';

test('assert.containsAllDeepKeys', () => {
  assert.containsAllDeepKeys(
    new Map([
      [{ one: 'one' }, 'valueOne'],
      [1, 2],
    ]),
    { one: 'one' }
  );
  assert.containsAllDeepKeys(
    new Map([
      [{ one: 'one' }, 'valueOne'],
      [{ two: 'two' }, 'valueTwo'],
    ]),
    [{ one: 'one' }, { two: 'two' }]
  );
  assert.containsAllDeepKeys(new Set([{ one: 'one' }, { two: 'two' }]), {
    one: 'one',
  });
  assert.containsAllDeepKeys(new Set([{ one: 'one' }, { two: 'two' }]), [
    { one: 'one' },
    { two: 'two' },
  ]);
});

doesNotHaveAnyDeepKeys ​

  • 타입: <T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string) => void

object가 제공된 keys 중 어느 것도 가지지 않는지 단언합니다. Set과 Map은 객체를 키로 가질 수 있으므로 이 단언을 사용하여 깊은 비교를 수행할 수 있습니다. 키 배열 대신 단일 객체를 제공할 수도 있으며, 해당 객체의 키가 예상되는 키 집합으로 사용됩니다.

ts
import { assert, test } from 'vitest';

test('assert.doesNotHaveAnyDeepKeys', () => {
  assert.doesNotHaveAnyDeepKeys(
    new Map([
      [{ one: 'one' }, 'valueOne'],
      [1, 2],
    ]),
    { thisDoesNot: 'exist' }
  );
  assert.doesNotHaveAnyDeepKeys(
    new Map([
      [{ one: 'one' }, 'valueOne'],
      [{ two: 'two' }, 'valueTwo'],
    ]),
    [{ twenty: 'twenty' }, { fifty: 'fifty' }]
  );
  assert.doesNotHaveAnyDeepKeys(new Set([{ one: 'one' }, { two: 'two' }]), {
    twenty: 'twenty',
  });
  assert.doesNotHaveAnyDeepKeys(new Set([{ one: 'one' }, { two: 'two' }]), [
    { twenty: 'twenty' },
    { fifty: 'fifty' },
  ]);
});

doesNotHaveAllDeepKeys ​

  • 타입: <T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string) => void

object가 제공된 keys 중 적어도 하나를 가지지 않는지 단언합니다. Set과 Map은 객체를 키로 가질 수 있으므로 이 단언을 사용하여 깊은 비교를 수행할 수 있습니다. 키 배열 대신 단일 객체를 제공할 수도 있으며, 해당 객체의 키가 예상되는 키 집합으로 사용됩니다.

ts
import { assert, test } from 'vitest';

test('assert.doesNotHaveAllDeepKeys', () => {
  assert.doesNotHaveAllDeepKeys(
    new Map([
      [{ one: 'one' }, 'valueOne'],
      [1, 2],
    ]),
    { thisDoesNot: 'exist' }
  );
  assert.doesNotHaveAllDeepKeys(
    new Map([
      [{ one: 'one' }, 'valueOne'],
      [{ two: 'two' }, 'valueTwo'],
    ]),
    [{ twenty: 'twenty' }, { one: 'one' }]
  );
  assert.doesNotHaveAllDeepKeys(new Set([{ one: 'one' }, { two: 'two' }]), {
    twenty: 'twenty',
  });
  assert.doesNotHaveAllDeepKeys(new Set([{ one: 'one' }, { two: 'two' }]), [
    { one: 'one' },
    { fifty: 'fifty' },
  ]);
});

throws ​

  • 타입:
    • (fn: () => void, errMsgMatcher?: RegExp | string, ignored?: any, message?: string) => void
    • (fn: () => void, errorLike?: ErrorConstructor | Error | null, errMsgMatcher?: RegExp | string | null, message?: string) => void
  • 별칭:
    • throw
    • Throw

errorLike가 Error 생성자이면, fn이 errorLike의 인스턴스인 오류를 던질 것이라고 단언합니다. errorLike가 Error 인스턴스이면, 던져진 오류가 errorLike와 동일한 인스턴스라고 단언합니다. errMsgMatcher가 제공되면, 던져진 오류가 errMsgMatcher와 일치하는 메시지를 가질 것이라고도 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.throws', () => {
  assert.throws(fn, 'Error thrown must have this msg');
  assert.throws(fn, /Error thrown must have a msg that matches this/);
  assert.throws(fn, ReferenceError);
  assert.throws(fn, errorInstance);
  assert.throws(
    fn,
    ReferenceError,
    'Error thrown must be a ReferenceError and have this msg'
  );
  assert.throws(
    fn,
    errorInstance,
    'Error thrown must be the same errorInstance and have this msg'
  );
  assert.throws(
    fn,
    ReferenceError,
    /Error thrown must be a ReferenceError and match this/
  );
  assert.throws(
    fn,
    errorInstance,
    /Error thrown must be the same errorInstance and match this/
  );
});

doesNotThrow ​

  • 타입: (fn: () => void, errMsgMatcher?: RegExp | string, ignored?: any, message?: string) => void
  • 타입: (fn: () => void, errorLike?: ErrorConstructor | Error | null, errMsgMatcher?: RegExp | string | null, message?: string) => void

errorLike가 Error 생성자이면, fn이 errorLike의 인스턴스인 오류를 던지지 않을 것이라고 단언합니다. errorLike가 Error 인스턴스이면, 던져진 오류가 errorLike와 동일한 인스턴스가 아니라고 단언합니다. errMsgMatcher가 제공되면, 던져진 오류가 errMsgMatcher와 일치하는 메시지를 가지지 않을 것이라고도 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.doesNotThrow', () => {
  assert.doesNotThrow(fn, 'Any Error thrown must not have this message');
  assert.doesNotThrow(fn, /Any Error thrown must not match this/);
  assert.doesNotThrow(fn, Error);
  assert.doesNotThrow(fn, errorInstance);
  assert.doesNotThrow(fn, Error, 'Error must not have this message');
  assert.doesNotThrow(fn, errorInstance, 'Error must not have this message');
  assert.doesNotThrow(fn, Error, /Error must not match this/);
  assert.doesNotThrow(fn, errorInstance, /Error must not match this/);
});

operator ​

  • 타입: (val1: OperatorComparable, operator: Operator, val2: OperatorComparable, message?: string) => void

operator를 사용하여 val1과 val2를 비교합니다.

ts
import { assert, test } from 'vitest';

test('assert.operator', () => {
  assert.operator(1, '<', 2, '모든 것이 ok입니다');
});

closeTo ​

  • 타입: (actual: number, expected: number, delta: number, message?: string) => void
  • 별칭: approximately

actual이 expected와 +/- delta 범위 내에서 같은지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.closeTo', () => {
  assert.closeTo(1.5, 1, 0.5, '숫자가 가깝습니다');
});

sameMembers ​

  • 타입: <T>(set1: T[], set2: T[], message?: string) => void

set1과 set2가 순서에 상관없이 동일한 멤버를 가지는지 단언합니다. 엄격한 동등성 검사(===)를 사용합니다.

ts
import { assert, test } from 'vitest';

test('assert.sameMembers', () => {
  assert.sameMembers([1, 2, 3], [2, 1, 3], '동일한 멤버');
});

notSameMembers ​

  • 타입: <T>(set1: T[], set2: T[], message?: string) => void

set1과 set2가 순서에 상관없이 동일한 멤버를 가지지 않는지 단언합니다. 엄격한 동등성 검사(===)를 사용합니다.

ts
import { assert, test } from 'vitest';

test('assert.notSameMembers', () => {
  assert.notSameMembers([1, 2, 3], [5, 1, 3], '동일한 멤버가 아님');
});

sameDeepMembers ​

  • 타입: <T>(set1: T[], set2: T[], message?: string) => void

set1과 set2가 순서에 상관없이 동일한 멤버를 가지는지 단언합니다. 깊은 동등성 검사를 사용합니다.

ts
import { assert, test } from 'vitest';

test('assert.sameDeepMembers', () => {
  assert.sameDeepMembers(
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    [{ b: 2 }, { a: 1 }, { c: 3 }],
    '동일한 깊은 멤버'
  );
});

notSameDeepMembers ​

  • 타입: <T>(set1: T[], set2: T[], message?: string) => void

set1과 set2가 순서에 상관없이 동일한 멤버를 가지지 않는지 단언합니다. 깊은 동등성 검사를 사용합니다.

ts
import { assert, test } from 'vitest';

test('assert.notSameDeepMembers', () => {
  assert.notSameDeepMembers(
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    [{ b: 2 }, { a: 1 }, { c: 3 }],
    '동일한 깊은 멤버가 아님'
  );
});

sameOrderedMembers ​

  • 타입: <T>(set1: T[], set2: T[], message?: string) => void

set1과 set2가 동일한 순서로 동일한 멤버를 가지는지 단언합니다. 엄격한 동등성 검사(===)를 사용합니다.

ts
import { assert, test } from 'vitest';

test('assert.sameOrderedMembers', () => {
  assert.sameOrderedMembers([1, 2, 3], [1, 2, 3], '동일한 순서의 멤버');
});

notSameOrderedMembers ​

  • 타입: <T>(set1: T[], set2: T[], message?: string) => void

set1과 set2가 동일한 순서로 동일한 멤버를 가지지 않는지 단언합니다. 엄격한 동등성 검사(===)를 사용합니다.

ts
import { assert, test } from 'vitest';

test('assert.notSameOrderedMembers', () => {
  assert.notSameOrderedMembers(
    [1, 2, 3],
    [2, 1, 3],
    '동일한 순서의 멤버가 아님'
  );
});

sameDeepOrderedMembers ​

  • 타입: <T>(set1: T[], set2: T[], message?: string) => void

set1과 set2가 동일한 순서로 동일한 멤버를 가지는지 단언합니다. 깊은 동등성 검사를 사용합니다.

ts
import { assert, test } from 'vitest';

test('assert.sameDeepOrderedMembers', () => {
  assert.sameDeepOrderedMembers(
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    '동일한 깊은 순서의 멤버'
  );
});

notSameDeepOrderedMembers ​

  • 타입: <T>(set1: T[], set2: T[], message?: string) => void

set1과 set2가 동일한 순서로 동일한 멤버를 가지지 않는지 단언합니다. 깊은 동등성 검사를 사용합니다.

ts
import { assert, test } from 'vitest';

test('assert.notSameDeepOrderedMembers', () => {
  assert.notSameDeepOrderedMembers(
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    [{ a: 1 }, { b: 2 }, { z: 5 }],
    '동일한 깊은 순서의 멤버가 아님'
  );
  assert.notSameDeepOrderedMembers(
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    [{ b: 2 }, { a: 1 }, { c: 3 }],
    '동일한 깊은 순서의 멤버가 아님'
  );
});

includeMembers ​

  • 타입: <T>(superset: T[], subset: T[], message?: string) => void

subset의 모든 멤버가 superset에 순서에 상관없이 포함되는지 단언합니다. 엄격한 동등성 검사(===)를 사용합니다. 중복은 무시됩니다.

ts
import { assert, test } from 'vitest';

test('assert.includeMembers', () => {
  assert.includeMembers([1, 2, 3], [2, 1, 2], '멤버 포함');
});

notIncludeMembers ​

  • 타입: <T>(superset: T[], subset: T[], message?: string) => void

subset의 모든 멤버가 superset에 순서에 상관없이 포함되지 않는지 단언합니다. 엄격한 동등성 검사(===)를 사용합니다. 중복은 무시됩니다.

ts
import { assert, test } from 'vitest';

test('assert.notIncludeMembers', () => {
  assert.notIncludeMembers([1, 2, 3], [5, 1], '멤버 포함 안 됨');
});

includeDeepMembers ​

  • 타입: <T>(superset: T[], subset: T[], message?: string) => void

subset의 모든 멤버가 superset에 순서에 상관없이 포함되는지 단언합니다. 깊은 동등성 검사를 사용합니다. 중복은 무시됩니다.

ts
import { assert, test } from 'vitest';

test('assert.includeDeepMembers', () => {
  assert.includeDeepMembers(
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    [{ b: 2 }, { a: 1 }, { b: 2 }],
    '깊은 멤버 포함'
  );
});

notIncludeDeepMembers ​

  • 타입: <T>(superset: T[], subset: T[], message?: string) => void

subset의 모든 멤버가 superset에 순서에 상관없이 포함되지 않는지 단언합니다. 깊은 동등성 검사를 사용합니다. 중복은 무시됩니다.

ts
import { assert, test } from 'vitest';

test('assert.notIncludeDeepMembers', () => {
  assert.notIncludeDeepMembers(
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    [{ b: 2 }, { f: 5 }],
    '깊은 멤버 포함 안 됨'
  );
});

includeOrderedMembers ​

  • 타입: <T>(superset: T[], subset: T[], message?: string) => void

subset이 superset의 첫 번째 요소부터 시작하여 동일한 순서로 superset에 포함되는지 단언합니다. 엄격한 동등성 검사(===)를 사용합니다.

ts
import { assert, test } from 'vitest';

test('assert.includeOrderedMembers', () => {
  assert.includeOrderedMembers([1, 2, 3], [1, 2], '순서 있는 멤버 포함');
});

notIncludeOrderedMembers ​

  • 타입: <T>(superset: T[], subset: T[], message?: string) => void

subset이 superset의 첫 번째 요소부터 시작하여 동일한 순서로 superset에 포함되지 않는지 단언합니다. 엄격한 동등성 검사(===)를 사용합니다.

ts
import { assert, test } from 'vitest';

test('assert.notIncludeOrderedMembers', () => {
  assert.notIncludeOrderedMembers(
    [1, 2, 3],
    [2, 1],
    '순서 있는 멤버 포함 안 됨'
  );
  assert.notIncludeOrderedMembers(
    [1, 2, 3],
    [2, 3],
    '순서 있는 멤버 포함 안 됨'
  );
});

includeDeepOrderedMembers ​

  • 타입: <T>(superset: T[], subset: T[], message?: string) => void

subset이 superset의 첫 번째 요소부터 시작하여 동일한 순서로 superset에 포함되는지 단언합니다. 깊은 동등성 검사를 사용합니다.

ts
import { assert, test } from 'vitest';

test('assert.includeDeepOrderedMembers', () => {
  assert.includeDeepOrderedMembers(
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    [{ a: 1 }, { b: 2 }],
    '깊은 순서 있는 멤버 포함'
  );
});

notIncludeDeepOrderedMembers ​

  • 타입: <T>(superset: T[], subset: T[], message?: string) => void

subset이 superset의 첫 번째 요소부터 시작하여 동일한 순서로 superset에 포함되지 않는지 단언합니다. 깊은 동등성 검사를 사용합니다.

ts
import { assert, test } from 'vitest';

test('assert.notIncludeDeepOrderedMembers', () => {
  assert.notIncludeDeepOrderedMembers(
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    [{ a: 1 }, { f: 5 }],
    '깊은 순서 있는 멤버 포함 안 됨'
  );
  assert.notIncludeDeepOrderedMembers(
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    [{ b: 2 }, { a: 1 }],
    '깊은 순서 있는 멤버 포함 안 됨'
  );
  assert.notIncludeDeepOrderedMembers(
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    [{ b: 2 }, { c: 3 }],
    '깊은 순서 있는 멤버 포함 안 됨'
  );
});

oneOf ​

  • 타입: <T>(inList: T, list: T[], message?: string) => void

객체도 배열도 아닌 inList 값이 평면 배열 list에 나타나는지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.oneOf', () => {
  assert.oneOf(1, [2, 1], '목록에서 찾을 수 없음');
});

changes ​

  • 타입: <T>(modifier: Function, object: T, property: string, message?: string) => void

modifier 함수가 object의 property 값을 변경하는지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.changes', () => {
  const obj = { val: 10 };
  function fn() {
    obj.val = 22;
  }
  assert.changes(fn, obj, 'val');
});

changesBy ​

  • 타입: <T>(modifier: Function, object: T, property: string, change: number, message?: string) => void

modifier 함수가 object의 property 값을 change만큼 변경하는지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.changesBy', () => {
  const obj = { val: 10 };
  function fn() {
    obj.val += 2;
  }
  assert.changesBy(fn, obj, 'val', 2);
});

doesNotChange ​

  • 타입: <T>(modifier: Function, object: T, property: string, message?: string) => void

modifier 함수가 object의 property 값을 변경하지 않는지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.doesNotChange', () => {
  const obj = { val: 10 };
  function fn() {
    obj.val += 2;
  }
  assert.doesNotChange(fn, obj, 'val', 2);
});

changesButNotBy ​

  • 타입: <T>(modifier: Function, object: T, property: string, change:number, message?: string) => void

modifier 함수가 object의 property 또는 modifier 반환 값을 change만큼 변경하지 않는지 단언합니다. (즉, 변경은 발생하지만 change만큼은 아님)

ts
import { assert, test } from 'vitest';

test('assert.changesButNotBy', () => {
  const obj = { val: 10 };
  function fn() {
    obj.val += 10;
  }
  assert.changesButNotBy(fn, obj, 'val', 5);
});

increases ​

  • 타입: <T>(modifier: Function, object: T, property: string, message?: string) => void

modifier 함수가 숫자 object의 property 값을 증가시키는지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.increases', () => {
  const obj = { val: 10 };
  function fn() {
    obj.val = 13;
  }
  assert.increases(fn, obj, 'val');
});

increasesBy ​

  • 타입: <T>(modifier: Function, object: T, property: string, change: number, message?: string) => void

modifier 함수가 숫자 object의 property 값 또는 modifier 반환 값을 change만큼 증가시키는지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.increasesBy', () => {
  const obj = { val: 10 };
  function fn() {
    obj.val += 10;
  }
  assert.increasesBy(fn, obj, 'val', 10);
});

doesNotIncrease ​

  • 타입: <T>(modifier: Function, object: T, property: string, message?: string) => void

modifier 함수가 숫자 object의 property 값을 증가시키지 않는지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.doesNotIncrease', () => {
  const obj = { val: 10 };
  function fn() {
    obj.val = 8;
  }
  assert.doesNotIncrease(fn, obj, 'val');
});

increasesButNotBy ​

  • 타입: <T>(modifier: Function, object: T, property: string, change: number, message?: string) => void

modifier 함수가 숫자 object의 property 값 또는 modifier 반환 값을 change만큼 증가시키지 않는지 단언합니다. (즉, 증가는 발생하지만 change만큼은 아님)

ts
import { assert, test } from 'vitest';

test('assert.increasesButNotBy', () => {
  const obj = { val: 10 };
  function fn() {
    obj.val += 15;
  }
  assert.increasesButNotBy(fn, obj, 'val', 10);
});

decreases ​

  • 타입: <T>(modifier: Function, object: T, property: string, message?: string) => void

modifier 함수가 숫자 object의 property 값을 감소시키는지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.decreases', () => {
  const obj = { val: 10 };
  function fn() {
    obj.val = 5;
  }
  assert.decreases(fn, obj, 'val');
});

decreasesBy ​

  • 타입: <T>(modifier: Function, object: T, property: string, change: number, message?: string) => void

modifier 함수가 숫자 object의 property 값 또는 modifier 반환 값을 change만큼 감소시키는지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.decreasesBy', () => {
  const obj = { val: 10 };
  function fn() {
    obj.val -= 5;
  }
  assert.decreasesBy(fn, obj, 'val', 5);
});

doesNotDecrease ​

  • 타입: <T>(modifier: Function, object: T, property: string, message?: string) => void

modifier 함수가 숫자 object의 property 값을 감소시키지 않는지 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.doesNotDecrease', () => {
  const obj = { val: 10 };
  function fn() {
    obj.val = 15;
  }
  assert.doesNotDecrease(fn, obj, 'val');
});

doesNotDecreaseBy ​

  • 타입: <T>(modifier: Function, object: T, property: string, change: number, message?: string) => void

modifier 함수가 숫자 object의 property 값 또는 modifier 반환 값을 change만큼 감소시키지 않는지 단언합니다. (즉, 감소는 발생하지만 change만큼은 아님)

ts
import { assert, test } from 'vitest';

test('assert.doesNotDecreaseBy', () => {
  const obj = { val: 10 };
  function fn() {
    obj.val = 5;
  }
  assert.doesNotDecreaseBy(fn, obj, 'val', 1);
});

decreasesButNotBy ​

  • 타입: <T>(modifier: Function, object: T, property: string, change: number, message?: string) => void

modifier 함수가 숫자 object의 property 값 또는 modifier 반환 값을 change만큼 감소시키지 않는지 단언합니다. (즉, 감소는 발생하지만 change만큼은 아님)

ts
import { assert, test } from 'vitest';

test('assert.decreasesButNotBy', () => {
  const obj = { val: 10 };
  function fn() {
    obj.val = 5;
  }
  assert.decreasesButNotBy(fn, obj, 'val', 1);
});

ifError ​

  • 타입: <T>(object: T, message?: string) => void

object가 거짓 값이 아니면 오류를 던지고, 참 값이면 단언이 실패합니다. 이는 Chai가 Node의 assert 클래스를 대체할 수 있도록 추가되었습니다.

ts
import { assert, test } from 'vitest';

test('assert.ifError', () => {
  const err = new Error('I am a custom error');
  assert.ifError(err); // Rethrows err!
});

isExtensible ​

  • 타입: <T>(object: T, message?: string) => void
  • 별칭: extensible

object가 확장 가능한지(새 속성을 추가할 수 있는지) 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.isExtensible', () => {
  assert.isExtensible({});
});

isNotExtensible ​

  • 타입: <T>(object: T, message?: string) => void
  • 별칭: notExtensible

object가 확장 불가능한지(새 속성을 추가할 수 없는지) 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.isNotExtensible', () => {
  const nonExtensibleObject = Object.preventExtensions({});
  const sealedObject = Object.seal({});
  const frozenObject = Object.freeze({});

  assert.isNotExtensible(nonExtensibleObject);
  assert.isNotExtensible(sealedObject);
  assert.isNotExtensible(frozenObject);
});

isSealed ​

  • 타입: <T>(object: T, message?: string) => void
  • 별칭: sealed

object가 봉인되었는지(새 속성을 추가할 수 없고 기존 속성을 제거할 수 없는지) 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.isSealed', () => {
  const sealedObject = Object.seal({});
  const frozenObject = Object.freeze({});

  assert.isSealed(sealedObject);
  assert.isSealed(frozenObject);
});

isNotSealed ​

  • 타입: <T>(object: T, message?: string) => void
  • 별칭: notSealed

object가 봉인되지 않았는지(새 속성을 추가할 수 있고 기존 속성을 제거할 수 있는지) 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.isNotSealed', () => {
  assert.isNotSealed({});
});

isFrozen ​

  • 타입: <T>(object: T, message?: string) => void
  • 별칭: frozen

객체가 동결되었는지(새 속성을 추가할 수 없고 기존 속성을 수정할 수 없는지) 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.isFrozen', () => {
  const frozenObject = Object.freeze({});
  assert.frozen(frozenObject);
});

isNotFrozen ​

  • 타입: <T>(object: T, message?: string) => void
  • 별칭: notFrozen

object가 동결되지 않았는지(새 속성을 추가할 수 있고 기존 속성을 수정할 수 있는지) 단언합니다.

ts
import { assert, test } from 'vitest';

test('assert.isNotFrozen', () => {
  assert.isNotFrozen({});
});

isEmpty ​

  • 타입: <T>(target: T, message?: string) => void
  • 별칭: empty

target에 값이 포함되어 있지 않은지 단언합니다. 배열과 문자열의 경우 length 속성을 확인합니다. Map 및 Set 인스턴스의 경우 size 속성을 확인합니다. 함수가 아닌 객체의 경우 자체 열거 가능한 문자열 키의 개수를 가져옵니다.

ts
import { assert, test } from 'vitest';

test('assert.isEmpty', () => {
  assert.isEmpty([]);
  assert.isEmpty('');
  assert.isEmpty(new Map());
  assert.isEmpty({});
});

isNotEmpty ​

  • 타입: <T>(object: T, message?: string) => void
  • 별칭: notEmpty

target에 값이 포함되어 있는지 단언합니다. 배열과 문자열의 경우 length 속성을 확인합니다. Map 및 Set 인스턴스의 경우 size 속성을 확인합니다. 함수가 아닌 객체의 경우 자체 열거 가능한 문자열 키의 개수를 가져옵니다.

ts
import { assert, test } from 'vitest';

test('assert.isNotEmpty', () => {
  assert.isNotEmpty([1, 2]);
  assert.isNotEmpty('34');
  assert.isNotEmpty(new Set([5, 6]));
  assert.isNotEmpty({ key: 7 });
});
Pager
이전expectTypeOf
다음assertType

MIT 라이선스 하에 배포되었습니다.

Copyright (c) 2021-Present Vitest Team

https://vitest.dev/api/assert

MIT 라이선스 하에 배포되었습니다.

Copyright (c) 2021-Present Vitest Team