Dorito
QnA [Jest] What is the difference between describe and it in Jest?
Dorito
Dorito's Dev
Dorito
전체
오늘
어제
  • 분류 전체보기 (33)
    • 재밌는 개발글이지만 아직 미분류 (6)
    • Infra (2)
      • ELK stack (2)
    • 인프라 (0)
    • 백엔드 (3)
      • 🐈️ Nest.js (3)
    • 프론트엔드 (0)
      • 🐏️ Next.js (0)
    • 알고리즘 (12)
      • 프로그래머스 (8)
      • 리트코드 (1)
      • SQL (1)
      • SQL-1 (2)
    • 궁금증 해결 (8)
      • 개념 (7)
      • 에러 (0)
      • 구현 (0)
    • 비공개 (0)
    • 잡동사니 (1)

블로그 메뉴

  • 글쓰기
  • 홈
  • 태그
  • 방명록
  • 관리

공지사항

인기 글

태그

  • ELK Stack
  • study
  • error-log
  • CachManager
  • JavaScript
  • typescript
  • web
  • Elasticsearch
  • react
  • 에러 해결
  • nestjs
  • Next.js
  • redis
  • Infra

최근 댓글

최근 글

hELLO · Designed By 정상우.
궁금증 해결/개념

QnA [Jest] What is the difference between describe and it in Jest?

2022. 12. 19. 16:53

제목: What is the difference between describe and it in Jest?
질문 날짜: 2022-09-29
태그: #jest
관련 글: [[Making Test Code at Controller layer]] [[Making GetByAuther Test Code (Moking)]][[Nest js Create 테스트코드]]


질문 내용

https://stackoverflow.com/questions/32055287/what-is-the-difference-between-describe-and-it-in-jest

질문 답변 (해결 방안)

describe breaks your test suite into components. Depending on your test strategy, you might have a describe for each function in your class, each module of your plugin, or each user-facing piece of functionality.

You can also nest describes to further subdivide the suite.

it is where you perform individual tests. You should be able to describe each test like a little sentence, such as "it calculates the area when the radius is set". You shouldn't be able to subdivide tests further-- if you feel like you need to, use describe instead.

describe('Circle class', function() {
  describe('area is calculated when', function() {
    it('sets the radius', function() { ... });
    it('sets the diameter', function() { ... });
    it('sets the circumference', function() { ... });
  });
});

As the jest docs says, test and it are the same: https://jestjs.io/docs/en/api#testname-fn-timeout

test(name, fn, timeout)
Also under the alias: it(name, fn, timeout)

and describe is just for when you prefer your tests to be organized into groups: https://jestjs.io/docs/en/api#describename-fn

describe(name, fn)

describe(name, fn) creates a block that groups together several related tests.
For example, if you have a myBeverage object that is supposed to be delicious but not sour, you could test it with:

const myBeverage = {
  delicious: true,
  sour: false,
};

describe('my beverage', () => {
  test('is delicious', () => {
    expect(myBeverage.delicious).toBeTruthy();
  });

  test('is not sour', () => {
    expect(myBeverage.sour).toBeFalsy();
  });
});

This isn't required - you can write the test blocks directly at the top level. But this can be handy if you prefer your tests to be organized into groups.


저작자표시 (새창열림)

'궁금증 해결 > 개념' 카테고리의 다른 글

Schema와 Table 차이 (mySQL , PostgreSQL)  (0) 2022.12.20
QnA [Java] 스택 자료구조 쓸 때 뭘 써야하는가  (0) 2022.12.19
QnA [Java] Interface Naming convention  (0) 2022.12.19
spyOn()과 jest.fn()의 차이  (1) 2022.12.05
타입스크립트 Interface, Type의 차이와 관련 연산자 (타입 합칠 때 & 사용)  (0) 2022.12.03
'궁금증 해결/개념' 카테고리의 다른 글
  • Schema와 Table 차이 (mySQL , PostgreSQL)
  • QnA [Java] 스택 자료구조 쓸 때 뭘 써야하는가
  • QnA [Java] Interface Naming convention
  • spyOn()과 jest.fn()의 차이
Dorito
Dorito
"Premature optimization is the root of all evil" - Donald Knuth
상단으로

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.