더북(TheBook)
    verify(input) {
        if ([SATURDAY, SUNDAY].includes(this.dayOfWeek())) {
            throw new Error("It's the weekend!");
        }
        const errors = [];
        // 더 많은 코드가 여기에 있다.
        return errors;
    }
}

// stub-time/02-inject-object/password-verifier-time01.spec.js
describe('verifier', () => {
    test('class constructor: on weekends, throws exception', () => {
        const alwaysSunday = () => SUNDAY;
        const verifier = new PasswordVerifier([], alwaysSunday);
        expect(() => verifier.verify('anything'))
            .toThrow("It's the weekend!");
    });
});

예제 3-10은 3.6절의 생성자 함수 설계 방식을 소개한 예제 3-9와 구조가 비슷하다.

신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.