81
59

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Jestのクイックリファレンス

Last updated at Posted at 2017-06-05

概要

Jest関数のクイックリファレンスです。
基本的なものを中心としており、モック機能には触れていません。
すべてを網羅しているわけではありませんので、詳しくは 公式 を参照してください。

A === B

test('toBe', () => {
  expect(A).toBe(B);
});

A !== B

test('not.toBe', () => {

});

A === NULL

test('toBeNull', () => {
  expect(A).toBeNull();
});

A !== NULL

test('not.toBeNull', () => {
  expect(A).not.toBeNull();
});

A === undefined

test('toBeUndefined', () => {
  expect(A).toBeUndefined();
});

A !== undefined

test('toBeDefined', () => {
  expect(A).toBeDefined();
});

A == true

test('toBeTruthy', () => {
  expect(A).toBeTruthy();
});

A == false

test('toBeFalsy', () => {
  expect(A).toBeFalsy();
});

A >= B

test('toBeGreaterThanOrEqual', () => {
  expect(A).toBeGreaterThanOrEqual(B);
});

A > B

test('toBeGreaterThan', () => {
  expect(A).toBeGreaterThan(B);
});

A <= B

test('toBeLessThanOrEqual', () => {
  expect(A).toBeLessThanOrEqual(B);
});

A < B

test('toBeLessThan', () => {
  expect(A).toBeLessThan(B);
});

A === B (連想配列の比較)

test('toEqual', () => {
  expect(A).toEqual(B);
});

A !== B (連想配列の比較)

test('toEqual', () => {
  expect(A).not.toEqual(B);
});

A === B (少数を含む比較)

test('toBeCloseTo', () => {
  expect(A).toBeCloseTo(B, 比較少数桁);
});

A に B (正規表現)が含まれる

test('toMatch', () => {
  expect(A).toMatch(B);
});

A(配列)に B (配列)が含まれる

test('toContainEqual', () => {
  expect(A).toContainEqual(B);
});

A(配列)に Bが含まれる

test('toContain', () => {
  expect(A).toContain(B);
});

A (オブジェクト)に B (オブジェクト)が含まれる

test('toMatchObject', () => {
  expect(A).toMatchObject(B);
});

A.length === B

test('toHaveLength', () => {
  expect(A).toHaveLength(B);
});

A.length !== B

test('not.toHaveLength', () => {
  expect(A).not.toHaveLength(B);
});

A に B プロパティが存在する

test('not.toHaveLength', () => {
  expect(A).toHaveProperty(B);
});

A に B プロパティが存在しない

test('not.toHaveLength', () => {
  expect(A).not.toHaveProperty(B);
});

A で例外が発生した

test('toThrow', () => {
  expect(A).toThrow();
});

A で発生した例外の Throw が B である

test('toThrowError', () => {
  expect(A).toThrowError(B);
});
81
59
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
81
59

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?