항상 그렇듯이 빈 함수에서 시작한다(예제 2-26).
예제 2-26 빈 Aop.around 함수
소스 파일 2장\AOP\Aop_00.js
Aop = { around: function(fnName, advice, fnObj) { // 처음 버전이라 하는 일이 없다. } };
첫 번째 테스트(예제 2-27)는 Aop.around가 원본 함수를 어드바이스로 대체하는지 확인한다.
예제 2-27 Aop.around가 어드바이스를 실행하는지 테스트
소스 파일 2장\AOP\Aop_01_tests.js
describe(‘Aop’, function() { describe(‘Aop.around(fnName, advice, targetObj)’, function() { it(‘타깃 함수를 호출 시 어드바이스를 실행하도록 한다’, function() { var targetObj = { targetFn: function () { } }; var executedAdvice = false; var advice = function() { executedAdvice = true; }; Aop.around(‘targetFn’, advice, targetObj); targetObj.targetFn(); expect(executedAdvice).toBe(true); }); }); });