Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gareth Whittaker committed Feb 24, 2017
1 parent 5d4ee10 commit 747bcde
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "rxjs-animation-loop",
"version": "0.1.4",
"version": "0.1.5",
"description": "This module provides a game / animation loop based upon requestAnimationFrame.",
"author": "Gareth Whittaker <[email protected]>",
"scripts": {
"compile": "babel src -d dist",
"prepublish": "npm run compile",
"test": "ava src/index.spec.js",
"example-multiple-subscribers": "npm run compile; node dist/examples/multiple-subscribers.js",
"example-pausing-game-loop": "npm run compile; node dist/examples/pausing-game-loop.js"
},
Expand All @@ -28,7 +29,9 @@
},
"license": "MIT",
"devDependencies": {
"ava": "0.18.2",
"babel-cli": "6.22.2",
"babel-preset-es2015": "6.22.0"
"babel-preset-es2015": "6.22.0",
"sinon": "1.17.7"
}
}
48 changes: 48 additions & 0 deletions src/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import test from 'ava'
import sinon from 'sinon'
import { Observable } from 'rxjs/Observable'
import { BehaviorSubject } from 'rxjs/BehaviorSubject'
import { animationLoop } from '../dist'

let nextSpy
let gameLoop

test.beforeEach(t => {
nextSpy = sinon.spy(BehaviorSubject.prototype, 'next')

gameLoop = animationLoop()
})

test.afterEach(t => {
nextSpy.restore()
})

test('start', t => {
gameLoop.start()

t.true(nextSpy.calledOnce)
t.true(nextSpy.calledWithExactly(true))
})

test('stop', t => {
gameLoop.stop()

t.true(nextSpy.calledOnce)
t.true(nextSpy.calledWithExactly(false))
})

test('subscribe', t => {
const observerStub = sinon.stub()
const subscriberStub = sinon.stub()

const subscribeStub = sinon.stub(Observable.prototype, 'subscribe').returns(subscriberStub)

const gameLoopSubscriber = gameLoop.subscribe(observerStub)

t.true(subscribeStub.calledOnce)
t.true(subscribeStub.calledWithExactly(observerStub))

t.is(gameLoopSubscriber, subscriberStub)

subscribeStub.restore()
})

0 comments on commit 747bcde

Please sign in to comment.