context_builder

    0.0.2 • Public • Published

    ContextBuilder

    This helps you to build DOM test environment without browser nor global pollution.

    INSTALL

    npm install context_builder
    

    HOW TO USE

    {ContextBuilder} = require 'context_builder'
     
    env = new ContextBuilder
      html: "<span id='item'> item </span>"
      scripts: [
        "jquery.js"
      ]
     
    env.build ->
      env.run ->
        # you can touch browser object like on browser 
        $('#item').text() #=> item 
     
      window? #=> false 
      env.ctx.window? #=> true 
     

    Test Example

    TestRunner is tuned for Mocha BDD Style.

    {TestEnv} = require 'context_builder'
    ck = require 'coffeekup' # npm install coffeekup 
     
    settings =
      root: __dirname
      html: ck.render ->
        div id:'hoge'-> 'div'
      scripts: [
        "lib/jquery.js"
        "lib/underscore.js"
        "lib/backbone.js"
      ]
     
    env = new TestEnv settings
    {_do_async} = env
     
    describe 'hoge'->
      beforeEach (done)->
        env.build done
     
      it 'should have id hoge'_do ->
        ok $('#hoge').size() is  1
     
      it 'should callback with timeout'_async ->
        ok $('#hoge').size() is  1
        setTimeout done100
     
    $ mocha --compilers coffee:coffee-script --ignore-leaks test.coffee
    

    "_do" and "_async" wrap contextify. In lambda after that, you can code like on browser.

    TODO

    • change implicit done on _async
    • wrap describe and it

    Keywords

    none

    Install

    npm i context_builder

    DownloadsWeekly Downloads

    0

    Version

    0.0.2

    License

    BSD

    Last publish

    Collaborators

    • mizchi