SORU
7 Mayıs 2013, Salı


Elde Jasmine ile çalışmak requirejs

Ben ilk RequireJS için yeni ve Yasemin bile daha yeni olduğumu söylemek istiyorum.

Bazı sorunlar SpecRunner ve JS gerektirir yaşıyorum. Uzi Kilon ve Ben Nadel (diğerleri ile birlikte) vaazlarını takip ediyorum ve bazı yardım ettiler ama hala bazı sorunlar yaşıyorum.

Eğer testi (özellikle bir tanesi, bir Tür hata düşünemiyorum) atılmış bir hata varsa spec runner html ekran olacak gibi görünüyor. Bu javascript içinde bazı sorunları olduğunu söylüyor. Ancak, ben bu hatayı düzeltmek sonra HTML artık görüntülenir.Yapamam test runner gösterilmesi için. Birisi bu soruna neden olacak bir şey benim koduyla yanlış bulabilir?

Burada benimdizin yapısı:

Root 
|-> lib
    |-> jasmine
        |-> lib (contains all of the jasmine lib)
        |-> spec
        |-> src
    |-> jquery (jquery js file)
    |-> require (require js file) 
index.html (spec runner) specRunner.js

İşteSpecRunner (dizin) HTML:

<!doctype html>
<html lang="en">
    <head>
        <title>Javascript Tests</title>

        <link rel="stylesheet" href="lib/jasmine/lib/jasmine.css">

        <script src="lib/jasmine/lib/jasmine.js"></script>
        <script src="lib/jasmine/lib/jasmine-html.js"></script>
        <script src="lib/jquery/jquery.js"></script>
        <script data-main="specRunner" src="lib/require/require.js"></script>

        <script>
            require({ paths: { spec: "lib/jasmine/spec" } }, [
                    // Pull in all your modules containing unit tests here.
                    "spec/notepadSpec"
                ], function () {
                    jasmine.getEnv().addReporter(new jasmine.HtmlReporter());
                    jasmine.getEnv().execute();
                });
        </script>

    </head>

<body>
</body>
</html>

İştespecRunner.js (config)

require.config({
    urlArgs: 'cb='   Math.random(),
    paths: {
        jquery: 'lib/jquery',
        jasmine: 'lib/jasmine/lib/jasmine',
        'jasmine-html': 'lib/jasmine/lib/jasmine-html',
        spec: 'lib/jasmine/spec/'
    },
    shim: {
        jasmine: {
            exports: 'jasmine'
        },
        'jasmine-html': {
            deps: ['jasmine'],
            exports: 'jasmine'
        }
    }
});

Burada bir spec:

require(["../lib/jasmine/src/notepad"], function (notepad) {
    describe("returns titles", function() {
        expect(notepad.noteTitles()).toEqual("");


    });
});

Not Defteri kaynağı:

define(['lib/jasmine/src/note'], function (note) {

    var notes = [
        new note('pick up the kids', 'dont forget to pick  up the kids'),
        new note('get milk', 'we need two gallons of milk')
    ];


    return {
        noteTitles: function () {
            var val;

            for (var i = 0, ii = notes.length; i < ii; i  ) {
                //alert(notes[i].title);
                val  = notes[i].title   ' ';
            }

            return val;
        }
    };
});

Ve Not kaynak (JIC):

define(function (){
    var note = function(title, content) {
        this.title = title;
        this.content = content;
    };

    return note;
});

Uygulama ile ilgili olarak, yolun doğru olduğundan emin yaptık. Bu çalışma aldığımda çok iğrenç değil mi ki bu yollar yapılandırma ile oynayabilirsiniz.

CEVAP
13 Mayıs 2013, PAZARTESİ


Bu biraz deneme yanılma ile çalıştırmayı başardım. Ana sorun değil görüşler oluşturmak istediğiniz ihtiyaç yazarken, define kullanmak istediğiniz oldu:

Özgün:

require(["/lib/jasmine/src/notepad"], function (notepad) {
    describe("returns titles", function() {
        expect(notepad.noteTitles()).toEqual("pick up the kids get milk");


    });
});

Çalışma:

define(["lib/jasmine/src/notepad"], function (notepad) {
    describe("returns titles", function () {

        it("something", function() {

            expect(notepad.noteTitles()).toEqual("pick up the kids get milk ");
        });

    });
});

, RequireJS kullanırken, istediğiniz bir Şey gerektiren netleşti biraz araştırma yaptıktan sonra() kullanmak define (şimdi oldukça açık görünüyor sanırım) bir sarılmış olması gerekir. , Specrunner.js dosyasında, gerekli testleri (bu nedenle "" görüşler. tanımlama ihtiyacı yürütürken kullanılır görebilirsiniz

Diğer konu, görüşler oluştururken, açıklayan() VE() gerekli (sadece bu örnek gönderildi varmış gibi tarif).

Özgün:

describe("returns titles", function() {
        expect(notepad.noteTitles()).toEqual("pick up the kids get milk");


    });

Çalışma:

describe("returns titles", function () {

        it("something", function() {

            expect(notepad.noteTitles()).toEqual("pick up the kids get milk ");
        });

    });

Ben de test runner var ama bu bir yeniden yerini değiştirdiler ve testlerin sonucu değiştirmedi.

Yine, burada dosyalar değişti:

note.js:aynı kaldı

notepad.js:aynı kaldı

index.html:

<!doctype html>
<html lang="en">
    <head>
        <title>Javascript Tests</title>
        <link rel="stylesheet" href="lib/jasmine/lib/jasmine.css">
        <script data-main="specRunner" src="lib/require/require.js"></script>
    </head>

    <body>
    </body>
</html>

specRunner.js:

require.config({
    urlArgs: 'cb='   Math.random(),
    paths: {
        jquery: 'lib/jquery',
        'jasmine': 'lib/jasmine/lib/jasmine',
        'jasmine-html': 'lib/jasmine/lib/jasmine-html',
        spec: 'lib/jasmine/spec/'
    },
    shim: {
        jasmine: {
            exports: 'jasmine'
        },
        'jasmine-html': {
            deps: ['jasmine'],
            exports: 'jasmine'
        }
    }
});


require(['jquery', 'jasmine-html'], function ($, jasmine) {

    var jasmineEnv = jasmine.getEnv();
    jasmineEnv.updateInterval = 1000;

    var htmlReporter = new jasmine.HtmlReporter();

    jasmineEnv.addReporter(htmlReporter);

    jasmineEnv.specFilter = function (spec) {
        return htmlReporter.specFilter(spec);
    };

    var specs = [];

    specs.push('lib/jasmine/spec/notepadSpec');



    $(function () {
        require(specs, function (spec) {
            jasmineEnv.execute();
        });
    });

});

notepadSpec.js:

define(["lib/jasmine/src/notepad"], function (notepad) {
    describe("returns titles", function () {

        it("something", function() {

            expect(notepad.noteTitles()).toEqual("pick up the kids get milk");
        });

    });
});

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • 8bitdigitaltv

    8bitdigitalt

    31 AĞUSTOS 2011
  • GamingAndTech

    GamingAndTec

    16 NİSAN 2013
  • GOTO Conferences

    GOTO Confere

    3 EKİM 2011