久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 javascript 認為文檔“準備好"之前,如何讓

How can I get my jasmine tests fixtures to load before the javascript considers the document to be quot;readyquot;?(在 javascript 認為文檔“準備好之前,如何讓我的 jasmine 測試裝置加載?) - IT屋-程序員軟件開發技術
本文介紹了在 javascript 認為文檔“準備好"之前,如何讓我的 jasmine 測試裝置加載?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我相當確定問題在于設置為在 $(document).ready 上運行的 jquery 綁定沒有可用的夾具 html.因此,當我的事件發生旨在通過 jquery 函數對 DOM 進行更改時,什么也沒有發生,我的測試也失敗了.我在這里看到了這個問題的解決方案",但是那個解決方案這對我有用,需要更改我的工作 jquery 函數以綁定 .live 方法而不是 .click 方法.我對此有兩個問題.首先,我不想更改我的工作代碼,以便測試能夠正確通過.測試框架應該測試代碼是否可以在應用程序中工作,其中 DOM 加載和 javascript 綁定以正確的順序發生.我對解決方案的第二個問題是 .on 和 .delegate 由于某種原因都不起作用,唯一最終起作用的是使用 .live 方法,該方法目前正在被棄用.總之,我想弄清楚如何更改我的測試或測試框架本身,以便在 $(document).ready 中運行的函數之前加載固定裝置.

I am fairly certain that the issue is that the jquery bindings set to run on $(document).ready do not have the fixture html available to them. So when my events occur that are intended to make a change to the DOM via a jquery function, nothing happens, and my tests fail. I saw a "solution" to this problem here, but that solution which did work for me, required changing my working jquery function to bind with the .live method instead of the .click method. I have two issue with this. First I do not want to have to change my working code so that the tests will pass properly. The testing framework ought to test whether the code will work in the app, where the DOM load and the javascript bindings occur in the correct order. The second issue I have with the solution is that .on and .delegate both did not work for some reason and the only thing that ended up working was to use the .live method which is currently in the process of being deprecated. In conclusion, I would like to figure out how to change either my tests or the testing framework itself, such that the fixtures are loaded before the functions that run in $(document).ready.

我正在使用 rails 3.2.8,并且設置了兩個不同的分支來進行 jasmine 測試.其中一個分支使用 jasminerice gem,另一個使用 jasmine-rails gem.Javascript 和 jQuery(使用 .live 方法時)測試都在這兩種設置中正確通過.

I am working with rails 3.2.8 and I have two different branches set up to experiment with jasmine testing. One of the branches uses the jasminerice gem and the other uses the jasmine-rails gem. The Javascript and jQuery(when using the .live method) tests all pass properly in both of these set-ups.

這里是使用茉莉花的分支的描述:

Here is a description of the branch using jasminerice:

以下是我的 Gemfile.lock 文件中描述 jasmine 和 jQuery 設置的行:

Here are the lines from my Gemfile.lock file describing the jasmine and jQuery set-up:

jasminerice (0.0.9)
  coffee-rails
  haml
jquery-rails (2.1.3)
  railties (>= 3.1.0, < 5.0)
  thor (~> 0.14)

Jasminerice 默認包含 jasmine-jquery 擴展.jasmine-jQuery 擴展提供了我在測試中使用的 toHaveText 方法.

Jasminerice includes the jasmine-jquery extension by default. The jasmine-jQuery extension provides the toHaveText method I am using in the tests.

直接位于 spec/javascripts 目錄中的測試文件 jasmine_jquery_test.js 包含以下內容:

The test file jasmine_jquery_test.js which is located directly within the spec/javascripts directory contains this content:

#= require application

describe ("my basic jasmine jquery test", function(){

    beforeEach(function(){
        $('<a id="test_link" href="somewhere.html">My test link</a>').appendTo('body');
    });

    afterEach(function(){
        $('a#test_link').remove();
    });

    it ("does some basic jQuery thing", function () {
        $('a#test_link').click();
        expect($("a#test_link")).toHaveText('My test link is now longer');
    });

    it ("does some the same basic jQuery thing with a different trigger type", function () {
        $('a#test_link').trigger('click');
        expect($("a#test_link")).toHaveText('My test link is now longer');
    });

});
describe ('subtraction', function(){

    var a = 1;
    var b = 2;

    it("returns the correct answer", function(){
        expect(subtraction(a,b)).toBe(-1);
    });

});

我位于 app/assets/javascripts 目錄中的 javascript 文件 tests.js 包含以下內容:

My javascript file tests.js which is located in the app/assets/javascripts dir has this content:

function subtraction(a,b){
    return a - b;
}

jQuery (function($) {
/* 
    The function I would rather use - 
    $("a#test_link").click(changeTheTextOfTheLink)
    function changeTheTextOfTheLink(e) {
        e.preventDefault()
        $("a#test_link").append(' is now longer');
    }
*/

    $("a#test_link").live('click', function(e) {
        e.preventDefault();
        $("a#test_link").append(' is now longer');
    });

});

我位于同一 app/assets/javascripts 目錄中的 application.js 文件包含以下內容:

My application.js file located in the same app/assets/javascripts dir has this content:

//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require vendor
//= require_tree . 

并且jasmine-rails分支的描述可以在我的第一個 jasmine 測試相關的 stackoverflow 問題.

And the description of the jasmine-rails branch can be found in the content of my first jasmine test related stackoverflow question.

如果有人知道如何操作測試,以便在加載固定裝置后運行 $(document).ready 函數,我非常想聽聽您的想法?

So if anyone has an idea how to manipulate the tests such that the $(document).ready functions are run after the fixtures are loaded I would very much like to hear your thoughts?

推薦答案

將 jQuery 直接添加到 html 夾具對我來說可以獲得所需的行為.這并不完全是這個問題的答案,但我開始相信它是目前可用的最佳解決方案.我在 jasmine-rails gem 設置中所做的更改,我還沒有在 jasminerice 分支中嘗試過.

Adding the jQuery directly to the html fixture worked for me to get the desired behavior. It is not exactly an answer to this question, but I am starting to believe it's the best solution currently available. My changes where made in the jasmine-rails gem set-up and I haven't yet tried it in the jasminerice branch.

這是我的測試文件:

describe ("my basic jasmine jquery test", function(){

    beforeEach(function(){
        loadFixtures('myfixture.html');
    });

    it ("does some basic jQuery thing", function () {
        $('a#test_link').click();
        expect($("a#test_link")).toHaveText('My test link is now longer');
    });

    it ("does the same basic jQuery thing with a different event initiation method", function () {
        $('a#test_link').trigger('click');
        expect($("a#test_link")).toHaveText('My test link is now longer');
    });

});
describe ('substraction', function(){

    var a = 1;
    var b = 2;

    it("returns the correct answer", function(){
        expect(substraction(a,b)).toBe(-1);
    });

});

這是我的夾具文件:

<a id="test_link" href="somewhere.html">My test link</a>

<script>
    $("a#test_link").click(changeTheTextOfTheLink)
    function changeTheTextOfTheLink(e) {
        e.preventDefault()
        $("a#test_link").append(' is now longer');
    }
</script>

這篇關于在 javascript 認為文檔“準備好"之前,如何讓我的 jasmine 測試裝置加載?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What do jasmine runs and waitsFor actually do?(jasmine 運行和等待實際上是做什么的?)
How to provide mock files to change event of lt;input type=#39;file#39;gt; for unit testing(如何提供模擬文件來更改 lt;input type=filegt; 的事件用于單元測試)
How to unit test a chained method using Jasmine(如何使用 Jasmine 對鏈式方法進行單元測試)
How do I inject $rootScope into an AngularJS unit test?(如何將 $rootScope 注入 AngularJS 單元測試?)
Jasmine - How to spy on a function call within a function?(Jasmine - 如何監視函數中的函數調用?)
jasmine test fails with undefined is not a function(evaluating $browser.$$checkUrlChange())(茉莉花測試失敗,未定義不是函數(評估 $browser.$$checkUrlChange()))
主站蜘蛛池模板: 99色播| 亚洲人成人一区二区在线观看 | 人人99 | h网站在线观看 | 日操夜操 | 国产一区免费视频 | 亚洲一区二区视频 | 在线视频91 | 日韩一二三区视频 | 日韩免费av | 日本久久久久久 | 国产欧美在线观看 | 欧美二区在线 | 中国一级大毛片 | 亚洲欧美中文日韩在线v日本 | 四虎永久免费黄色影片 | 国产精品久久在线观看 | 一区二区三区欧美在线 | 国产精品久久久久久久久久久免费看 | 福利电影在线 | 91麻豆精品国产91久久久久久 | 91大神在线资源观看无广告 | 一本久久a久久精品亚洲 | 亚洲成人在线网 | 99久久婷婷国产综合精品 | 男女视频在线观看免费 | 久久久91精品国产一区二区三区 | 欧美日韩国产综合在线 | 中文字幕一区二区三区四区五区 | 精品91久久 | 91精品国产乱码久久久 | 中文字幕中文字幕 | 成人激情视频免费观看 | 久久精品网| 日韩中文字幕久久 | 亚洲国产精品一区二区第一页 | av一区二区在线观看 | a级在线观看 | 久久久久久国产精品免费免费狐狸 | 蜜桃久久 | 欧美成人h版在线观看 |