8000 GitHub - burtcorp/karen
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Mar 21, 2023. It is now read-only.

burtcorp/karen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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).

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  
0