Coder Social home page Coder Social logo

mocha-jsdom's Introduction

Mocha tests under Node.js with a jsdom

This is a proof of concept project to find a convenient way of running Mocha tests via the Node.js runner using jsdom, to create a more browser like environment. You might want to do that to test symantic aspects of your program in Node.js without having to load the entire thing in a browser, mostly for performance reasons.

The callback based ways described in jsdom's page will have a little hard time to trigger Mocha to run your suites, so to do this you need to use the methods described by jsdom's docs as "For the hardcore". Actually it isn't that difficult, and this little project shows how to do it.

How to try:

Manual (at least for now). Clone, then prepare your directory by running a npm install:

$ npm install

You should see lots of output.

Have a look at the test.js file. It initializes a jsdom object in the describe function and points a closure local 'document' to it in a way that preceding tests will have an environment that reasonably much resembles a web browser. The run.sh script will run the spec.

A somewhat uglier but more realistic simulation for larger codebases would be to assign the return value of the call to jsdom.jsdom to global.document.

mocha-jsdom's People

Contributors

jacob414 avatar

Stargazers

 avatar

Watchers

 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.