๊ฐ๋จํ ํ ์คํธ ์์ฑ
์ฝ๋1. toBe()
//fn.js
const fn = {
add : (num1,num2) => num1+num2
}
module.exports = fn
//fn.test.js
const fn = require('./fn')
test('1์ 1์ด์ผ',()=>{
expect(1).toBe(1)
})
test('2๋ํ๊ธฐ 3์ 5์ผ',()=>{
expect(fn.add(2,3)).toBe(5)
})
test('3๋ํ๊ธฐ 3์ 5์ผ',()=>{
expect(fn.add(3,3)).toBe(5)
})
๊ฒฐ๊ณผ1.
์ฝ๋2. toBe(), not.toBe()
const fn = require('./fn')
test('1์ 1์ด์ผ',()=>{
expect(1).toBe(1)
})
test('2๋ํ๊ธฐ 3์ 5์ผ',()=>{
expect(fn.add(2,3)).toBe(5)
})
test('3๋ํ๊ธฐ 3์ 5๊ฐ ์๋์ผ',()=>{
expect(fn.add(3,3)).not.toBe(5)
})
๊ฒฐ๊ณผ2
์ฝ๋3. toBe(), toEqual()
//fn.js
const fn = {
add : (num1,num2) => num1+num2,
makeUser:(name,age)=>({name,age})
}
module.exports = fn
//fn.test.js
const fn = require('./fn')
test('์ด๋ฆ๊ณผ ๋์ด๋ฅผ ์ ๋ฌ ๋ฐ์์ ๊ฐ์ฒด๋ฅผ ๋ณํ', ()=>{
expect(fn.makeUser('iseo',27)).toBe({
name:'iseo',
age:27,
})
})
test('์ด๋ฆ๊ณผ ๋์ด๋ฅผ ์ ๋ฌ ๋ฐ์์ ๊ฐ์ฒด๋ฅผ ๋ณํ', ()=>{
expect(fn.makeUser('iseo',27)).toEqual({
name:'iseo',
age:27,
})
})
๊ฒฐ๊ณผ3
์ฝ๋4. toEqual(), toStrictEqual()
const fn = require('./fn')
test('์ด๋ฆ๊ณผ ๋์ด๋ฅผ ์ ๋ฌ ๋ฐ์์ ๊ฐ์ฒด๋ฅผ ๋ณํ', ()=>{
expect(fn.makeUser('iseo',27)).toEqual({
name:'iseo',
age:27,
})
})
test('์ด๋ฆ๊ณผ ๋์ด๋ฅผ ์ ๋ฌ ๋ฐ์์ ๊ฐ์ฒด๋ฅผ ๋ณํ', ()=>{
expect(fn.makeUser('iseo',27)).toStrictEqual({
name:'iseo',
age:27,
})
})
๊ฒฐ๊ณผ4
์ฝ๋5. ์ธ์ ์ถ๊ฐ
//fn.js
const fn = {
add : (num1,num2) => num1+num2,
makeUser:(name,age,gender)=>({name,age,gender:undefined})
}
module.exports = fn
//fn.test.js
const fn = require('./fn')
test('์ด๋ฆ๊ณผ ๋์ด๋ฅผ ์ ๋ฌ ๋ฐ์์ ๊ฐ์ฒด๋ฅผ ๋ณํ', ()=>{
expect(fn.makeUser('iseo',27)).toEqual({
name:'iseo',
age:27,
})
})
test('์ด๋ฆ๊ณผ ๋์ด๋ฅผ ์ ๋ฌ ๋ฐ์์ ๊ฐ์ฒด๋ฅผ ๋ณํ', ()=>{
expect(fn.makeUser('iseo',27)).toStrictEqual({
name:'iseo',
age:27,
})
})
์ฝ๋6. toBeNull(),toBeUndefined(),toBeDefined(),toBeTruthy(),toBeFalsy()
//fn.test.js
const fn = require('./fn')
//toBeNull
//toBeUndefined
//toBeDefined
test('null์ null์
๋๋ค',()=>{
expect(null).toBeNull()
})
//toBeTruthy
//toBeFalsy
test('0์ false์
๋๋ค',()=>{
expect(fn.add(1,-1)).toBeFalsy()
})
๊ฒฐ๊ณผ6
์ฝ๋7
const fn = require('./fn')
//toBeNull
//toBeUndefined
//toBeDefined
test('null์ null์
๋๋ค',()=>{
expect(null).toBeNull()
})
//toBeTruthy
//toBeFalsy
test('๋น์ด์์ง ์์ ๋ฌธ์์ด์ true',()=>{
expect(fn.add('Decision To','Leave')).toBeTruthy()
})
๋๊ธ