스파르타코딩클럽 내일배움캠프 Node.js 심화주차 강의를 들으며 공부한 것을 적은 것입니다.
npm i jest -D
{
...
"scripts" : {
"test": "jest"
}
...
}
module.exports = {
isEmail: (value) => {
const email = value || '';
if (email.split('@').length !== 2) {
return false;
} else if (email.includes(' ')) {
return false;
}
return true;
}
}
const { isEmail } = require('./validation');
test('입력한 이메일 주소에는 "@" 문자가 1개만 있어야 이메일 형식이다.', () => {
expect(isEmail('my-email@domain.com')).toEqual(true);
expect(isEmail('my-email@@@@domain.com')).toEqual(false);
expect(isEmail('my-emaildomain.com')).toEqual(false);
});
test('입력한 이메일 주소에 공백(스페이스)이 존재하면 이메일 형식이 아니다.', () => {
expect(isEmail('myemail@domain.com')).toEqual(true);
expect(isEmail('my email@domain.com')).toEqual(false);
});
// jest.config.js
module.exports = {
// 해당 패턴에 일치하는 경로가 존재할 경우 테스트를 하지 않고 넘어갑니다.
"testPathIgnorePatterns": ["/node_modules/"],
// 테스트 실행 시 각 TestCase에 대한 출력을 해줍니다.
verbose: true,
}
// package.json
{
...
"scripts": {
...
"test": "jest --forceExit",
"test:silent": "jest --silent --forceExit",
"test:coverage": "jest --coverage --forceExit",
"test:unit": "est __tests__/unit --forceExit",
"test:integration": "jest __tests__/integration --forceExit"
},
...
}