[javascript] Chai의 Assertion 메서드 중 문자열과 관련된 메서드는?
equal(str1, str2)
: 두 문자열이 정확히 일치하는지 확인합니다.notEqual(str1, str2)
: 두 문자열이 정확히 일치하지 않는지 확인합니다.include(substring)
: 문자열이 특정 부분 문자열을 포함하는지 확인합니다.match(regexp)
: 문자열이 정규식과 일치하는지 확인합니다.lengthOf(length)
: 문자열의 길이가 주어진 값과 일치하는지 확인합니다.startsWith(prefix)
: 문자열이 특정 접두어로 시작하는지 확인합니다.endsWith(suffix)
: 문자열이 특정 접미어로 끝나는지 확인합니다.
이러한 Assertion 메서드를 사용하여 문자열에 대한 다양한 테스트를 수행할 수 있습니다. Chai에는 기타 유용한 Assertion 메서드도 많이 있으니 필요한 경우 공식 문서를 참조하시기 바랍니다.
const { assert } = require('chai');
// 예시
assert.equal('hello', 'hello');
assert.notEqual('hello', 'world');
assert.include('hello', 'ell');
assert.match('hello', /^h/);
assert.lengthOf('hello', 5);
assert.startsWith('hello', 'he');
assert.endsWith('hello', 'lo');