-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throw TypeErrors on invalid inputs to AnimationEffectTiming #426
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,18 +33,17 @@ suite('timing-utilities', function() { | |
f = toTimingFunction('cubic-bezier(0, 1, 1, 0)'); | ||
assert.closeTo(f(0.104), 0.392, 0.01); | ||
|
||
function assertIsLinear(easing) { | ||
var f = toTimingFunction(easing); | ||
for (var i = 0; i <= 1; i += 0.1) { | ||
assert.equal(f(i), i, easing + ' is linear'); | ||
} | ||
function assertThrows(easing) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make this test easier to read, I think this function name should be more explicit about what it does. This is a bit long but maybe something like assertThrowsOnConversionToTimingFunction? assertInvalidEasingThrows? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
assert.throws(function() { | ||
toTimingFunction(easing); | ||
}, easing); | ||
} | ||
|
||
assertIsLinear('cubic-bezier(.25, 0.1, 0.25, 1.)'); | ||
assertIsLinear('cubic-bezier(0, 1, -1, 1)'); | ||
assertIsLinear('an elephant'); | ||
assertIsLinear('cubic-bezier(-1, 1, 1, 1)'); | ||
assertIsLinear('cubic-bezier(1, 1, 1)'); | ||
assertThrows('cubic-bezier(.25, 0.1, 0.25, 1.)'); | ||
assertThrows('cubic-bezier(0, 1, -1, 1)'); | ||
assertThrows('an elephant'); | ||
assertThrows('cubic-bezier(-1, 1, 1, 1)'); | ||
assertThrows('cubic-bezier(1, 1, 1)'); | ||
|
||
f = toTimingFunction('steps(10, end)'); | ||
assert.equal(f(0), 0); | ||
|
@@ -119,4 +118,24 @@ suite('timing-utilities', function() { | |
assert.equal(effectTF(6000), 0.5); | ||
assert.closeTo(effectTF2(6000), 0.8, 0.005); | ||
}); | ||
test('TypeErrors', function() { | ||
var timing = normalizeTimingInput({ | ||
iterationStart: 123, | ||
iterations: 456, | ||
duration: 789, | ||
easing: 'ease', | ||
}); | ||
|
||
assert.throws(function() { timing.iterationStart = -1; }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider testing more invalid values There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added NaN tests. |
||
assert.equal(timing.iterationStart, 123); | ||
|
||
assert.throws(function() { timing.iterations = -1; }); | ||
assert.equal(timing.iterations, 456); | ||
|
||
assert.throws(function() { timing.duration = -1; }); | ||
assert.equal(timing.duration, 789); | ||
|
||
assert.throws(function() { timing.easing = 'invalid timing function'; }); | ||
assert.equal(timing.easing, 'ease'); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this have an isNan check as well, like duration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added check, I realise now the NaN check is implicit in the IDL type.