Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: 테스트 관심사에 따른 describe 세분화 #80

Merged
merged 3 commits into from
Apr 27, 2024

Conversation

pengooseDev
Copy link
Contributor

@pengooseDev pengooseDev commented Apr 26, 2024

Overview

[Issue] 테스트코드 리팩터링 #79

  • 테스트코드의 관심사에 따라 describe를 그룹화 하였습니다.

Previous Code

describe('chosungIncludes', () => {
  it('should return true when "ㅍㄹㅌ" is entered for searching "프론트엔드"', () => {
    expect(chosungIncludes('프론트엔드', 'ㅍㄹㅌ')).toBe(true);
  });

  it('should return true when "ㅍㄹㅌ" is entered for searching "00프론트엔드"', () => {
    expect(chosungIncludes('00프론트엔드', 'ㅍㄹㅌ')).toBe(true);
  });

  it('should return false when "ㅍㅌ" is entered for searching "프론트엔드"', () => {
    expect(chosungIncludes('프론트엔드', 'ㅍㅌ')).toBe(false);
  });

  it('should return true when "ㅍㄹㅌㅇㄷㄱㅂㅈ" is entered for searching "프론트엔드 개발자"', () => {
    expect(chosungIncludes('프론트엔드 개발자', 'ㅍㄹㅌㅇㄷㄱㅂㅈ')).toBe(true);
  });

  // ...codes
});

Refactored Code

import { chosungIncludes } from './chosungIncludes';

describe('chosungIncludes', () => {
  describe('초성이 포함되어있다고 판단되는 경우', () => {
    it('should return true when "ㅍㄹㅌ" is entered for searching "프론트엔드"', () => {
      expect(chosungIncludes('프론트엔드', 'ㅍㄹㅌ')).toBe(true);
    });

    it('should return true when "ㅍㄹㅌ" is entered for searching "00프론트엔드"', () => {
      expect(chosungIncludes('00프론트엔드', 'ㅍㄹㅌ')).toBe(true);
    });

    it('should return true when "ㅍㄹㅌㅇㄷㄱㅂㅈ" is entered for searching "프론트엔드 개발자"', () => {
      expect(chosungIncludes('프론트엔드 개발자', 'ㅍㄹㅌㅇㄷㄱㅂㅈ')).toBe(true);
    });

    it('should return true when "ㅍㄹㅌㅇㄷ ㄱㅂㅈ" is entered for searching "프론트엔드 개발자"', () => {
      expect(chosungIncludes('프론트엔드 개발자', 'ㅍㄹㅌㅇㄷ ㄱㅂㅈ')).toBe(true);
    });
  });

  describe('초성이 포함되어있다고 판단되지 않는 경우', () => {
    it('should return false when "ㅍㅌ" is entered for searching "프론트엔드"', () => {
      expect(chosungIncludes('프론트엔드', 'ㅍㅌ')).toBe(false);
    });

    it('should return false when "ㅍㄹㅌㅇㄷ ㄱㅂㅈ" is entered for searching " "', () => {
      expect(chosungIncludes('프론트엔드 개발자', ' ')).toBe(false);
    });

    // ...codes
  });
});

hasSingleBatchim

홑받침이 맞다고 판단되는 경우는 기존 test description과 겹쳐 오히려 가독성을 저해할 수 있다고 판단하여 추가하지 않았습니다.

describe('hasSingleBatchim', () => {
  it('홑받침을 받으면 true를 반환한다.', () => { // ⛳️ describe를 추가하지 않음.
    expect(hasSingleBatchim('공')).toBe(true);
    expect(hasSingleBatchim('핫')).toBe(true);
    expect(hasSingleBatchim('양')).toBe(true);
    expect(hasSingleBatchim('신')).toBe(true);
  });

  describe('홑받침이 아니라고 판단되는 경우', () => {
    it('겹받침을 받으면 false를 반환한다.', () => {
      expect(hasSingleBatchim('값')).toBe(false);
      expect(hasSingleBatchim('읊')).toBe(false);
    });

    it('받침이 없는 문자를 받으면 false를 반환한다.', () => {
      expect(hasSingleBatchim('토')).toBe(false);
      expect(hasSingleBatchim('서')).toBe(false);
    });
  });
});

PR Checklist

  • I read and included theses actions below
  1. I have read the Contributing Guide
  2. I have written documents and tests, if needed.

Copy link

changeset-bot bot commented Apr 26, 2024

⚠️ No Changeset found

Latest commit: 952a8ce

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Apr 26, 2024

@pengooseDev is attempting to deploy a commit to the Toss Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Member

@evan-moon evan-moon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pengooseDev 기여 감사합니다. 테스트 케이스를 읽기가 한결 편해졌네요 👍

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.54%. Comparing base (dbeeeab) to head (952a8ce).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #80   +/-   ##
=======================================
  Coverage   97.54%   97.54%           
=======================================
  Files          13       13           
  Lines         204      204           
  Branches       45       45           
=======================================
  Hits          199      199           
  Misses          5        5           

@evan-moon evan-moon merged commit 18085b6 into toss:main Apr 27, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants