路宁(luning)的博客

    <<  Manage Mock Dependencies of Controllers with IoC Container | Home |
  • Share DOM Fixtures between JavaScript Unit Tests - [Javascript]

    2009-12-21

    For the JavaScript unit tests that operate DOM, it's quite handy if the DOM fixtures could be shared between tests. This involves how to load another HTML file from one HTML file for most of the JavaScript testing frameworks (like Screw.Unit and JSUnit), the prior file is the DOM fixture and the later file hosts the test codes.

    This blog demonstrates a way to do it through jQuery synchronized Ajax call. Below is the code skeleton of a test file:

    <html>
      <head>
        <script type="text/javascript" src="lib/jquery-1.3.2.js"></script>
      </head>
    
      <body>
        <div id="fixture">
          <script type="text/javascript">
            $.ajaxSetup({ async: false }); // Ajax will run in sync
            $("#fixture").load("fixtures/DOMFixture.html"); // replace inner html with loaded content
          </script>
        </div>
    
        <script type="text/javascript">
          // tests go here
        </script>
      </body>
    </html>
    

    This works for all the mainstream browsers including Firefox and IE.

    Another possible approach that I haven't verified in detail is that 1) create XML document element dynamically, 2) load fixture file to the element synchronously, then 3) append the element to the place holder DIV in test file.

     


    随机文章:

    Remove the Noisy Thread.Sleep and WaitForCondition from Selenium Tests 2009-05-14
    Code Snippet to Log All Events as They Are Triggered 2009-04-28
    A Quick Check of Javascript Code Quality 2009-03-30
    利用客户端Javascript代码简化Selenium测试 2008-12-23
    将客户端逻辑封装进Javascript对象,并用Jsunit做单元测试 2008-11-04

    收藏到:Del.icio.us
    Tag:Javascript Unit-Test Screw.Unit JQuery
    Cite url:
    luning published this at 13:41:55 | Edit | Continue This Topic | Forward | 分享 0
  • RSS EMail Me

Search

Latest logs

  • Share DOM Fixtures between JavaScript Unit Tests
  • Manage Mock Dependencies of Controllers with IoC Container
  • The Waste from Very Fat to Very Lean's Perspective
  • A Misleading Analogy between Software Development and Manufacturing
  • Selenium Test Powered by jQuery.parcel
  • Remove the Noisy Thread.Sleep and WaitForCondition from Selenium Tests
  • Code Snippet to Log All Events as They Are Triggered
  • A Quick Check of Javascript Code Quality
  • Implement Object Builder for Testing in a .NET Object Initializer Style
  • 看过《丰田现场管理方式》,30年前出版的书
全部日志>>

Comments

  • taowen:http://taowen.github.com/bay...
  • dewwind88:呵呵,我信!我也是自己深有同感~-网络上的陌生人,搜索到...
  • sean xu:项目忙完了吗?好像很久没写精益方面的文章了:)...
  • 菜头:good summary ^.^
  • luning:你是说如何确定适合自己team的switch频率吧,多尝...
  • jackie chen:LN,想问问:怎样计算switch pair rate ...
  • sabrina:路子分析的很有道理哦!...
  • sabrina:虽然我不是很懂技术,但是能看出你的用心,加油哦!...
  • ncholas ren:where is the 'continue...'
  • laura:不错,好好学习!

Categories

  • Lean[21]
  • Software Development[2]
  • Agile[15]
  • Life[1]
  • Economics[3]
  • Misc[0]
  • Test[7]
  • Javascript[3]

Tag

  • 敏捷[32]
  • 精益[29]
  • Agile[22]
  • 软件开发[19]
  • Lean[15]
More..