-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gareth Whittaker
committed
Feb 24, 2017
1 parent
5d4ee10
commit 747bcde
Showing
2 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
}, | ||
|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) |