karen
Test mocks for window, document and dom nodes
Last updated 3 years ago by rejeep .
MIT · Original npm · Tarball · package.json
$ cnpm install karen 
SYNC missed versions from official npm registry.

Karen

Karen is a collection of mock objects, for example window, document and node.

Installation

$ npm install karen --save-dev

API

These are the main mock objects:

  • MockWindow
  • MockDocument
  • MockElement
  • MockNode
  • MockLocation
  • MockNavigator
  • MockScreen
  • MockDate

See code/tests for resp class on how to use.

Usage

As a simple example, let's say we want to add some syntactic sugar around setTimeout, with the following API:

timer = Timer(window)
timer.delay 100, -> # do something

on 'event', ->
  timer.stop()

Here is the implementation of Timer:

Timer = (window) ->
  delay: (ms, callback) ->
    timeout = window.setTimeout(callback, ms)

    stop: ->
      window.clearTimeout(timeout)

And a simple test using Mocha.js:

describe 'Timer', ->
  it 'runs callback', (done) ->
    mockWindow = new MockWindow
    timer = Timer(mockWindow)
    timer.delay(100, done)
    mockWindow.tick(100)

Copyright

© 2014-2015 Burt AB, see LICENSE.txt (BSD 3-Clause).

Current Tags

  • 0.7.0                                ...           latest (3 years ago)

17 Versions

  • 0.7.0                                ...           3 years ago
  • 0.6.2                                ...           4 years ago
  • 0.6.1                                ...           4 years ago
  • 0.6.0                                ...           4 years ago
  • 0.5.0                                ...           5 years ago
  • 0.4.0                                ...           5 years ago
  • 0.3.4                                ...           5 years ago
  • 0.3.3                                ...           5 years ago
  • 0.3.2                                ...           5 years ago
  • 0.3.1                                ...           5 years ago
  • 0.3.0                                ...           5 years ago
  • 0.2.3                                ...           5 years ago
  • 0.2.2                                ...           5 years ago
  • 0.2.1                                ...           6 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (7)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |