Skip to content

Commit

Permalink
Change to aprroximately compare floats instead of equality
Browse files Browse the repository at this point in the history
  • Loading branch information
kimmobrunfeldt committed Dec 8, 2014
1 parent 23f0f16 commit 3d08aca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
"devDependencies": {
"bluebird": "^2.3.6",
"browserify": "^6.2.0",
"chai": "^1.10.0",
"chai-stats": "kimmobrunfeldt/chai-stats",
"commander": "^2.4.0",
"expect.js": "^0.3.1",
"grunt": "^0.4.5",
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-uglify": "^0.6.0",
Expand Down
30 changes: 18 additions & 12 deletions test/shared-behaviour.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// Tests which test shared behaviour of all progress bar shapes


var expect = require('expect.js');
var chai = require('chai');
var chaiStats = require('chai-stats');
chai.use(chaiStats);
var expect = chai.expect;

var utils = require('./utils');

var PRECISION = 2;


var sharedTests = function sharedTests() {
it('animate should change SVG path stroke-dashoffset property', function(done) {
Expand All @@ -19,12 +25,12 @@ var sharedTests = function sharedTests() {
});

it('bar should be empty after initialization', function() {
expect(this.bar.value()).to.be(0);
expect(this.bar.value()).to.almost.equal(0, PRECISION);
});

it('set should change value', function() {
this.bar.set(1);
expect(this.bar.value()).to.be(1);
expect(this.bar.value()).to.almost.equal(1, PRECISION);
});

it('animate should change value', function(done) {
Expand All @@ -33,11 +39,11 @@ var sharedTests = function sharedTests() {

var self = this;
setTimeout(function checkValueHasChanged() {
expect(self.bar.value()).not.to.be(1);
expect(self.bar.value()).not.to.almost.equal(1, PRECISION);
}, 100);

setTimeout(function checkAnimationHasCompleted() {
expect(self.bar.value()).to.be(0);
expect(self.bar.value()).to.almost.equal(0, PRECISION);
done();
}, 800);
});
Expand All @@ -54,18 +60,18 @@ var sharedTests = function sharedTests() {
}, 100);

setTimeout(function checkProgressAfterStop() {
expect(progressAfterStop).to.be(self.bar.value());
expect(progressAfterStop).to.almost.equal(self.bar.value(), PRECISION);
done();
}, 400);
});

it('destroy() should delete element', function() {
var svg = document.querySelector('svg');
expect(svg).not.to.be(null);
expect(svg).not.to.equal(null);

this.bar.destroy();
svg = document.querySelector('svg');
expect(svg).to.be(null);
expect(svg).to.equal(null);
});

it('destroy() should make object unusable', function() {
Expand All @@ -76,12 +82,12 @@ var sharedTests = function sharedTests() {
methodsShouldThrow.forEach(function(methodName) {
expect(function shouldThrow() {
self[methodName]();
}).to.throwError();
}).to.throw(Error);
});

expect(this.bar.svg).to.be(null);
expect(this.bar.path).to.be(null);
expect(this.bar.trail).to.be(null);
expect(this.bar.svg).to.equal(null);
expect(this.bar.path).to.equal(null);
expect(this.bar.trail).to.equal(null);
});
};

Expand Down
2 changes: 0 additions & 2 deletions test/test-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// CONTRIBUTING.md
// Supporting both has lead to some compromises.

var expect = require('expect.js');

var utils = require('./utils');
// https://github.com/mochajs/mocha/wiki/Shared-Behaviours
var sharedTests = require('./shared-behaviour');
Expand Down

0 comments on commit 3d08aca

Please sign in to comment.