[모던 JavaScript] 3.3 ~ 3.6 과제 정리

    SMALL
    • 3.3 주석
    • 3.4 닌자 코드
    • 3.5 테스트 자동화와 Mocha
    • 3.6 폴리필

    3.5 잘못된 점 찾기

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>잘못된 점 찾기</title>
    </head>
    <body>
        <script>
            it("주어진 숫자의 n 제곱", function() {
             let x = 5;
    
            let result = x;
            assert.equal(pow(x, 1), result);
    
            result *= x;
            assert.equal(pow(x, 2), result);
    
            result *= x;
            assert.equal(pow(x, 3), result);
            });
    
            // 3개의 test **
            // but test 함수는 pow 한 개 뿐 **
            // it을 분리 작성!**
    
            describe("주어진 숫자의 n 제곱"), function() {
                it("5를 1제곱하면 5", function(){
                    assert.equal(pow(5,1), 5);
                });
    
                it("5를 2제곱하면 25", function(){
                    assert.equal(pow(5,2), 25);
                });
    
                it("5를 3제곱하면 125", function(){
                    assert.equal(pow(5,3), 125);
                });
            }
    
            // ** it.only -> 원하는 it 블록만 실행
        </script>
    </body>
    </html>
    728x90

    댓글