Skip to content

Commit

Permalink
fix: fix string with decimal numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
aadityataparia committed May 3, 2019
1 parent f39438c commit 4ee46fb
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/sifrr.animate.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/sifrr.animate.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/sifrr.animate.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/sifrr.animate.module.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/sifrr.animate.module.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/animateone.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Bezier = require('./bezier');
const types = require('./types');
const digitRgx = /(\d+)/;
const digitRgx = /(\d+\.?\d*)/;

function animateOne({
target,
Expand Down
50 changes: 50 additions & 0 deletions test/browser/animate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ describe('animate', () => {
expect(target).to.deep.equal({ a: 100 });
});

it('works with single digit', async () => {
const { i, target } = await page.evaluate(async () => {
let i = 0, onUpdate = () => i++;
let target = { a: 0 };
await animate({
target,
to: {
a: 9
},
onUpdate,
time: 100
});

return { i, target };
});

expect(i).to.be.at.least(100/FRAME_TIME);
expect(target).to.deep.equal({ a: 9 });
});

it('works without from', async () => {
const { i, target } = await page.evaluate(async () => {
let i = 0, onUpdate = () => i++;
Expand Down Expand Up @@ -96,6 +116,36 @@ describe('animate', () => {
expect(Number(callBreak[3])).to.be.at.least(100);
});

it('works with decimal string', async () => {
const calls = await page.evaluate(async () => {
let calls = [], onUpdate = function(target, prop, val) {
calls.push(val);
};
let target = {
a: '0.567px'
};
await animate({
target,
to: {
a: '145.567px'
},
time: 100,
onUpdate
});

return calls;
});

expect(calls.length).to.be.at.least(100/FRAME_TIME);
expect(calls[0]).to.not.equal('145.567px');
expect(calls[calls.length - 1]).to.equal('145.567px');

const callBreak = calls[0].split(/(\d+.?\d+)/);
expect(Number(callBreak[1])).to.be.at.least(0);
expect(Number(callBreak[1])).to.be.at.most(145);
expect(calls[0].match(/\./g).length).to.equal(1);
});

it('works with string, no from value', async () => {
const calls = await page.evaluate(async () => {
let calls = [], onUpdate = function(target, prop, val) {
Expand Down

0 comments on commit 4ee46fb

Please sign in to comment.