Skip to content
Vitest 1
Main Navigation 가이드API구성고급
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 UI

브라우저 모드

소스 내 테스트

테스트 컨텍스트

테스트 환경

Matcher 확장하기

IDE 통합

디버깅

다른 테스트 러너와의 비교

마이그레이션 가이드

일반적인 오류

성능 향상

API

테스트 API 참조

Mock 함수

Vi

expect

expectTypeOf

assert

assertType

구성

Vitest 구성 파일 관리

Vitest 구성하기

이 페이지에서

assert ​

Vitest는 불변성을 검증하기 위해 chai의 assert 메서드를 재export합니다.

assert ​

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

주어진 expression이 truthy 값인지 확인합니다. truthy 값이 아니면 assertion이 실패합니다.

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

assertion 실패를 발생시킵니다.

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', '모든 truthy 값은 ok로 간주됩니다.');
  assert.isOk(false, 'false는 truthy 값이 아니므로 이 assertion은 실패합니다.');
});

isNotOk ​

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

주어진 value가 falsy 값인지 확인합니다.

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

test('assert.isNotOk', () => {
  assert.isNotOk('foo', 'truthy 값이므로 실패합니다.');
  assert.isNotOk(false, 'false는 falsy 값이므로 통과합니다.');
});

equal ​

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

actual과 expected가 non-strict 동등(==)한지 확인합니다.

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가 non-strict 부등(!=)한지 확인합니다.

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

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

strictEqual ​

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

actual과 expected가 strict 동등(===)한지 확인합니다.

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은 undefined가 아닙니다.');
});

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.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가 boolean 값인지 단언합니다.

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

const isReady = true;

test('assert.isBoolean', () => {
  assert.isBoolean(isReady, 'isReady는 boolean 값이 맞습니다.');
});

isNotBoolean ​

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

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

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

const isReady = 'sure';

test('assert.isNotBoolean', () => {
  assert.isNotBoolean(isReady, 'isReady는 boolean 값이 아닌 문자열입니다.');
});

typeOf ​

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

value의 타입이 Object.prototype.toString 메서드에 의해 결정된 타입 이름 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

value의 타입이 Object.prototype.toString 메서드에 의해 결정된 타입 이름 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.instanceOf(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는 점 표기법(dot notation) 또는 대괄호 표기법(bracket notation)을 사용하여 중첩된 속성을 참조하는 문자열입니다.

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는 점 표기법(dot notation) 또는 대괄호 표기법(bracket notation)을 사용하여 중첩된 속성을 참조하는 문자열입니다.

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는 점 표기법(dot notation) 또는 대괄호 표기법(bracket notation)을 사용하여 중첩된 속성을 참조하는 문자열입니다.

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는 점 표기법(dot notation) 또는 대괄호 표기법(bracket notation)을 사용하여 중첩된 속성을 참조하는 문자열입니다.

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는 점 표기법(dot notation) 또는 대괄호 표기법(bracket notation)을 사용하여 중첩된 속성을 참조하는 문자열입니다.

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'
  );
});

notDeepNestedPropertyVal ​

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

object가 property로 지정된 중첩된 속성을 직접 또는 상속받아 가지고 있지 않거나, 그 속성 값이 value와 깊은 비교를 통해 동일하지 않은지 확인합니다. property는 점 표기법(dot notation) 또는 대괄호 표기법(bracket notation)을 사용하여 중첩된 속성을 참조하는 문자열입니다.

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 속성 값이 예상 값인 length와 같은지 확인합니다.

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.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',
  ]);
});

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

fn이 오류를 던지는지 확인합니다.

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

fn이 오류를 던지지 않는지 확인합니다.

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, 'everything is 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, 'numbers are close');
});

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], 'same members');
});

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], 'not same members');
});

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 }],
    'same deep members'
  );
});

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 }],
    'same deep members'
  );
});

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], 'same ordered members');
});

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],
    'not same ordered members'
  );
});

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 }],
    'same deep ordered members'
  );
});

notSameDeepOrderedMembers ​

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

set1과 set2가 깊은 비교(deep equality)를 통해 동일한 순서로 동일한 멤버를 포함하지 않는지 확인합니다.

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

test('assert.notSameDeepOrderedMembers', () => {
  assert.notSameDeepOrderedMembers(
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    [{ a: 1 }, { b: 2 }, { z: 5 }],
    'not same deep ordered members'
  );
  assert.notSameDeepOrderedMembers(
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    [{ b: 2 }, { a: 1 }, { c: 3 }],
    'not same deep ordered members'
  );
});

includeMembers ​

  • Type: <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], 'include members');
});

notIncludeMembers ​

  • Type: <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], 'not include members');
});

includeDeepMembers ​

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

subset의 모든 멤버가 superset에 순서에 상관없이 깊은 비교(deep equality)를 통해 포함되는지 확인합니다. 중복된 멤버는 무시됩니다.

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

test('assert.includeDeepMembers', () => {
  assert.includeDeepMembers(
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    [{ b: 2 }, { a: 1 }, { b: 2 }],
    'include deep members'
  );
});

notIncludeDeepMembers ​

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

subset의 멤버 중 하나라도 superset에 깊은 비교(deep equality)를 통해 포함되지 않는지 확인합니다. 중복된 멤버는 무시됩니다.

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

test('assert.notIncludeDeepMembers', () => {
  assert.notIncludeDeepMembers(
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    [{ b: 2 }, { f: 5 }],
    'not include deep members'
  );
});

includeOrderedMembers ​

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

subset이 superset의 시작부터 동일한 순서로 포함되는지 확인합니다. 엄격한 동등성 검사(===)를 사용합니다. 즉, subset은 superset의 연속된 부분 배열이어야 합니다.

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

test('assert.includeOrderedMembers', () => {
  assert.includeOrderedMembers([1, 2, 3], [1, 2], 'include ordered members');
});

notIncludeOrderedMembers ​

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

subset이 superset의 시작부터 동일한 순서로 포함되지 않는지 확인합니다. 엄격한 동등성 검사(===)를 사용합니다. 즉, subset이 superset의 연속된 부분 배열이 아니어야 합니다.

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

test('assert.notIncludeOrderedMembers', () => {
  assert.notIncludeOrderedMembers(
    [1, 2, 3],
    [2, 1],
    'not include ordered members'
  );
  assert.notIncludeOrderedMembers(
    [1, 2, 3],
    [2, 3],
    'not include ordered members'
  );
});

includeDeepOrderedMembers ​

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

subset이 superset의 시작부터 동일한 순서로 깊은 비교(deep equality)를 통해 포함되는지 확인합니다. 즉, subset은 superset의 연속된 부분 배열이어야 합니다.

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

test('assert.includeDeepOrderedMembers', () => {
  assert.includeDeepOrderedMembers(
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    [{ a: 1 }, { b: 2 }],
    'include deep ordered members'
  );
});

notIncludeDeepOrderedMembers ​

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

subset이 superset의 시작부터 동일한 순서로 깊은 비교(deep equality)를 통해 포함되지 않는지 확인합니다. 즉, subset이 superset의 연속된 부분 배열이 아니어야 합니다.

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

test('assert.includeDeepOrderedMembers', () => {
  assert.notIncludeDeepOrderedMembers(
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    [{ a: 1 }, { f: 5 }],
    'not include deep ordered members'
  );
  assert.notIncludeDeepOrderedMembers(
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    [{ b: 2 }, { a: 1 }],
    'not include deep ordered members'
  );
  assert.notIncludeDeepOrderedMembers(
    [{ a: 1 }, { b: 2 }, { c: 3 }],
    [{ b: 2 }, { c: 3 }],
    'not include deep ordered members'
  );
});

oneOf ​

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

값 inList가 배열 list의 멤버 중 하나인지 확인합니다. inList는 객체나 배열이 아닌 원시 값이어야 합니다.

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

test('assert.oneOf', () => {
  assert.oneOf(1, [2, 1], 'Not found in list');
});

changes ​

  • Type: <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 ​

  • Type: <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 ​

  • Type: <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 ​

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

modifier 함수를 실행한 후 object의 property 값이 변경되었지만, 그 변경량이 정확히 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 ​

  • Type: <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 ​

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

modifier 함수를 실행한 후 숫자 타입인 object의 property 값이 정확히 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 ​

  • Type: <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 ​

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

modifier 함수를 실행한 후 숫자 타입인 object의 property 값이 증가했지만, 그 증가량이 정확히 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 ​

  • Type: <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 ​

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

modifier 함수를 실행한 후 숫자 타입인 object의 property 값이 정확히 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 ​

  • Type: <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 값을 change만큼 감소시키지 않는지 확인합니다. 또는 modifier 함수의 반환 값을 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 값을 감소시키지만, 특정 change 값만큼 감소시키지는 않는지 확인합니다. 또는 modifier 함수의 반환 값을 감소시키지만, 특정 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가 falsy 값이 아닌지 확인하고, truthy 값일 경우 예외를 발생시킵니다. 이는 chai가 Node의 assert 클래스를 대체할 수 있도록 하기 위해 추가되었습니다.

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

test('assert.ifError', () => {
  const err = new Error('I am a custom error');
  assert.ifError(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

object가 동결되었는지 확인합니다. 즉, 새로운 속성을 추가할 수 없고, 기존 속성을 수정할 수 없는지 확인합니다.

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

test('assert.isFrozen', () => {
  const frozenObject = Object.freeze({});
  assert.isFrozen(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>(target: 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) 2024 Mithril Contributors

https://v1.vitest.dev/api/assert

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

Copyright (c) 2024 Mithril Contributors