Skip to content

Commit

Permalink
Move test to tape; resolved #16
Browse files Browse the repository at this point in the history
  • Loading branch information
broadsw0rd committed Mar 25, 2017
1 parent 8fdb61c commit 993748c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ node_js:
- '4'
- '5'
- '6'
- '7'
after_script:
- npm run coveralls
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
],
"main": "dist/dynamica.js",
"devDependencies": {
"ava": "^0.16.0",
"babel-preset-es2015-loose-rollup": "^7.0.0",
"coveralls": "^2.11.12",
"nyc": "^8.1.0",
"rollup": "^0.34.12",
"rollup-plugin-babel": "^2.6.1",
"sinon": "^1.17.4",
"snazzy": "^4.0.1",
"tap-prettify": "0.0.2",
"tape": "^4.6.3",
"uglify-js": "^2.7.3"
},
"babel": {
Expand All @@ -46,7 +47,7 @@
},
"scripts": {
"check": "snazzy src/*.js test/*.js",
"test": "nyc --cache --reporter=html --reporter=lcov --reporter=text ava",
"test": "nyc --cache --reporter=html --reporter=lcov --reporter=text tap-prettify test/dynamica.test.js",
"build": "rollup -c",
"min": "uglifyjs -c -m -- dist/dynamica.js > dist/dynamica.min.js",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
Expand Down
62 changes: 56 additions & 6 deletions test/dynamica.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
var test = require('ava')
var test = require('tape')
var sinon = require('sinon')

var Animation = require('../dist/dynamica.js')

test.beforeEach(function (t) {
function beforeEach () {
Animation.instances = []
})
}

test('`Animation` should be defined', function (t) {
t.truthy(Animation)
beforeEach()

t.ok(Animation)
t.end()
})

test('`Animation#constructor()` should create new animation instance', function (t) {
beforeEach()

var animation = new Animation({
duration: 1000
})
Expand All @@ -23,27 +28,38 @@ test('`Animation#constructor()` should create new animation instance', function
t.true(animation.ease instanceof Function)
t.true(animation.next instanceof Array)
t.throws(() => Animation({ duration: 1000 }))
t.end()
})

test('`Animation#constructor()` should throw error if duration not passed', function (t) {
beforeEach()

function createAnimation () {
return new Animation()
}

t.throws(createAnimation)

t.end()
})

test('`Animation#start()` should start the animation', function (t) {
beforeEach()

var animation = new Animation({
duration: 1000
})
animation.start()

t.is(Animation.instances.length, 1)
t.not(Animation.instances.indexOf(animation), -1)

t.end()
})

test('`Animation#start()` should call onstart callback', function (t) {
beforeEach()

var animation = new Animation({
duration: 1000,
onstart: function () {}
Expand All @@ -53,9 +69,13 @@ test('`Animation#start()` should call onstart callback', function (t) {

animation.start()
t.is(onstart.callCount, 1)

t.end()
})

test('`Animation#cancel()` should stop the animation', function (t) {
beforeEach()

var animation = new Animation({
duration: 1000
})
Expand All @@ -65,10 +85,14 @@ test('`Animation#cancel()` should stop the animation', function (t) {
t.is(Animation.instances.length, 0)
t.is(Animation.instances.indexOf(animation), -1)

t.notThrows(() => animation.cancel())
t.doesNotThrow(() => animation.cancel())

t.end()
})

test('`Animation#cancel()` should call oncancel callback', function (t) {
beforeEach()

var animation = new Animation({
duration: 1000,
oncancel: function () {}
Expand All @@ -78,9 +102,13 @@ test('`Animation#cancel()` should call oncancel callback', function (t) {

animation.cancel()
t.is(oncancel.callCount, 1)

t.end()
})

test('`Animation#queue()` should add animation to the queue', function (t) {
beforeEach()

var animation = new Animation({
duration: 1000
})
Expand All @@ -91,9 +119,13 @@ test('`Animation#queue()` should add animation to the queue', function (t) {

t.is(animation.next.length, 1)
t.not(animation.next.indexOf(next), -1)

t.end()
})

test('`Animation#dequeue()` should remove animation from the queue', function (t) {
beforeEach()

var animation = new Animation({
duration: 1000
})
Expand All @@ -106,10 +138,14 @@ test('`Animation#dequeue()` should remove animation from the queue', function (t
t.is(animation.next.length, 0)
t.is(animation.next.indexOf(next), -1)

t.notThrows(() => animation.dequeue(next))
t.doesNotThrow(() => animation.dequeue(next))

t.end()
})

test('`Animation#started()` should indicate animation status', function (t) {
beforeEach()

var animation = new Animation({
duration: 1000
})
Expand All @@ -119,9 +155,13 @@ test('`Animation#started()` should indicate animation status', function (t) {

animation.cancel()
t.false(animation.started())

t.end()
})

test('`Animation#complete()` should immediately complete the animation', function (t) {
beforeEach()

var animation = new Animation({
duration: 1000
})
Expand All @@ -134,9 +174,13 @@ test('`Animation#complete()` should immediately complete the animation', functio

t.true(handler.getCall(0).calledWith(1))
t.true(next.started())

t.end()
})

test('`Animation#complete()` should call oncomplete callback', function (t) {
beforeEach()

var animation = new Animation({
duration: 1000,
oncomplete: function () {}
Expand All @@ -146,9 +190,13 @@ test('`Animation#complete()` should call oncomplete callback', function (t) {

animation.complete()
t.is(oncomplete.callCount, 1)

t.end()
})

test('`Animation.animate()` should animate the animation', function (t) {
beforeEach()

var animation = new Animation({
duration: 1000
})
Expand All @@ -172,4 +220,6 @@ test('`Animation.animate()` should animate the animation', function (t) {
Animation.animate(time + 1100)

t.true(handler.getCall(2).calledWith(1))

t.end()
})

0 comments on commit 993748c

Please sign in to comment.