그래서 DRY 방식으로 자동화 된 테스트를 구축하기 위해 주석을 대체하는 테스트 용 전처리 기가 있습니다. 그런 다음 정상적으로 실행할 수있는 파일을 생성합니다. 다음과 같이 테스트 단계 내에서 regexp를 사용해야 할 때 유일한 문제가 나타납니다.
.step(/^Search for special characters$/, function() {
client.setValue("input[type=text]", "@#$%^&*()_ -={}[]|\\\"':;? >.<,`©®ÉÖ]]™\"".replace(/[-[\]{}()*+?.,\\^$|"'#\s]/g, "\\$&")
}
물론 내가 끝내는 것은 다음과 같은 테스트 파일입니다.
client.setValue("input[type=text]", "@#$%^&*()_ -={}[]|\\\"':;? >.<,`©®ÉÖ]]™\"".replace(/[-[\]{}()*+?.,\\^$|"'#\s]/g, "\\//Search for special characters")
어쨌든 자바 스크립트에 "$ &를 일치 결과로 바꾸지 마십시오!"라고 말할 수 있습니까?
전체 워크 플로를 오해하지 않는 한 $$
작동하는 것 같습니다.
txt = '123';
step = function(re, fn) {
return txt.replace(re, fn.toString());
}
code = step(/^123$/, function() {
return "abc".replace(/./g, "$$&")
});
document.write(code);
document.write("<br>");
document.write(eval("(" + code + ")()"));
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다