GithubHelp home page GithubHelp logo

testdom's Introduction

Testdom

Testdom is a jsdom wrapper to help developers write test code that works both in the browser and in node.

It works by checking if a global document exists in it's current environment. If it does it bails out and expects the browser to provide all available browser globals. If a global document does not exists, it will create one using jsdom.

WANTED! PRs with more tested additional globals.

Install

npm install testdom

Usage

require('testdom')('<html><body></body></html>')
console.log(document)

Additional globals

Testdom supports an argument of additional globals that will be loaded (using require) only if no DOM exists. This way users can experiment with different modules as browser global replacements and polyfills.

require('testdom')('<html><body></body></html>', {
    localStorage : 'localStorage'
})
console.log(localStorage)

In the additional globals object the key is the name of the global the the value is the module name to be require'd.

Confirmed modules

A list of modules confirmed to work well as a global/polyfill for jsdom.

Global Module Notes
localStorage localStorage 404 link but npm install works
Promise es6-promises Different than es6-promise (singular).

Testling

Testling uses browserify to create a browser compatible bundle of your javascripts. Unfortunately jsdom is not compatible with browserify, so we have to tell testling to ignore it.

In your package.json add a browser field and add tell browserify to ignore jsdom.

$ vi package.json

...
"browser" : {
    "jsdom" : false
},
...

Since testdom only tries to require jsdom if no document exists; the browser will never reach that code and we are good. The tests will use the browser's DOM.

Changelog

1.0.1

  • Upgraded jsdom dependency from 2.x.x to 3.x.x

1.0.0

  • Removed non-jsdom dependencies (& globals)
  • Added ability to require non-jsdom modules only if DOM does not exists
  • Started list of working globals & polyfills

0.1.0

  • Pre changelog era. Who knows what went on.

enjoy.

testdom's People

Contributors

asbjornenge avatar andrewzey avatar gregglind avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.