Jest
ํ์ต ํค์๋
๐ค ํ
์คํธ ์ผ์ด์ค ์ ์ ํ๋ ๋ฐฉ๋ฒ
1. test ํจ์๋ก ๊ฐ๋ณ ํ
์คํธ๋ฅผ ๋์ดํ๋ ๋ฐฉ์
test('add', () => {
expect(add(1, 2)).toBe(3);
});2. BDD ์คํ์ผ๋ก ์ฃผ์ฒด-ํ์ ์ค์ฌ์ผ๋ก ํ
์คํธ๋ฅผ ์กฐ์งํํ๋ ๋ฐฉ์
describe('add', () => { // ์ฃผ์ฒด : add ํจ์
it('returns sum of two numbers', () => { // ํ์ : add ํจ์๊ฐ ๋ ์ซ์๋ฅผ ๋ํ ๊ฐ์ ๋ฐํํ๋ค.
expect(add(1, 2)).toBe(3);
});
});๐ค BDD ์คํ์ผ์ ๋ญ๊น?
๐ ๏ธ Jest ์ค์น ๋ฐ ์คํ ๋ฐฉ๋ฒ
1. Jest ์ค์น
2. Jest์์ TypeScript ์ฌ์ฉํ๋๋ก jest.config.js ํ์ผ ์์ฑ
jest.config.js ํ์ผ ์์ฑ3. Jest ์คํ
โ๏ธ Jest ๊ธฐ๋ณธ ์ฌ์ฉ ๋ฐฉ๋ฒ
๐ฏ Matchers๋ก ๋ค์ํ ๊ฒฐ๊ณผ ์์ธกํ๊ธฐ
.toBe
.toBe.toEqual
.toEqual๐งฉ Describe-Context-It (Describe-It) ํจํด
๐ค ๊ทธ๋ฃนํ ํ๋ค๋๊ฒ ๋ฌด์จ ์๋ฏธ ์ผ๊น?
Jest๋ฅผ ์ด์ฉํ ๊ฐ๋จํ TDD ์์
๐ ํ์ผ๋ช
: ํ์ผ์ด๋ฆ.test.ํ์ฅ์
ํ์ผ์ด๋ฆ.test.ํ์ฅ์๐ค test ํจ์๋ก ๊ฐ๋ณ ํ
์คํธ๋ฅผ ๋์ดํ๋ ๋ฐฉ์
๐ค BDD ์คํ์ผ๋ก ์ฃผ์ฒด-ํ์ ์ค์ฌ์ผ๋ก ํ
์คํธ๋ฅผ ์กฐ์งํํ๋ ๋ฐฉ์
๐ค ๋ค์ํ ๊ฒฝ์ฐ๊ฐ ๊ณ ๋ ค ๋์ด์ผ ํ๋ค๋ฉด? โ Describe-Context-It ํจํด
๐ ์ฐธ๊ณ
Last updated