ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • JQunit 사용하기 11
    javascript/JQunit 2015. 7. 24. 16:26
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title>QUnit Example01</title>
        <link rel="stylesheet" href="//code.jquery.com/qunit/qunit-1.18.0.css">
        <script src="//code.jquery.com/qunit/qunit-1.18.0.js"></script>
        <script type="text/javascript">
        // 테스트 코드를 넣는다.
        QUnit.test( "hello test"function( assert ) {
            assert.ok( 1 == "1""Passed!" );
        });
        test("세자리 아하면 그냥 리턴한다"function(){
            equal(setComma(1),1,"한자리는 그냥 반환한다.");
            equal(setComma(12),12,"두자리는 그냥 반환한다.");
            equal(setComma(123),123,"세자리는 그냥 반환한다.");
        });
        test("세자리가 넘으면 세자리마다 ,를 찍어 리턴한다"function(){
            equal(setComma(1234),"1,234","세자리가 넘으면 세자리마다 ,를 찍어 리턴한다.");
            equal(setComma(12345),"12,345","세자리가 넘으면 세자리마다 ,를 찍어 리턴한다.");
            equal(setComma(123456),"123,456","세자리가 넘으면 세자리마다 ,를 찍어 리턴한다.");
        });
       </script>
        <script type="text/javascript">
        // 구현코드를 넣는다.
        function setComma(num){
            var n = num + "";
            if(n.length >3)
                return n.replace(/(\d{3})$/,",$1");
            else
                return num;
        }    
       </script>
    </head>
    <body>
        <div id="qunit"></div>
        <div id="qunit-fixture"></div>
    </body>
    </html>
    cs


    'javascript > JQunit' 카테고리의 다른 글

    JQunit 사용하기 10  (0) 2015.07.24
    JQunit 사용하기 09  (0) 2015.07.24
    JQunit 사용하기 08  (0) 2015.07.24
    JQunit 사용하기 07  (0) 2015.07.24
    JQunit 사용하기 06  (0) 2015.07.24

    댓글

Designed by Tistory.