mirror of https://github.com/sveltejs/svelte
parent
f5bc3e3c84
commit
f76fac2973
@ -1,39 +1,29 @@
|
|||||||
export default {
|
export default {
|
||||||
test ( assert, component, target, window ) {
|
test ( assert, component, target, window, raf ) {
|
||||||
global.count = 0;
|
global.count = 0;
|
||||||
let now = 0;
|
|
||||||
let callback;
|
|
||||||
|
|
||||||
window.performance = { now: () => now };
|
|
||||||
global.requestAnimationFrame = cb => callback = cb;
|
|
||||||
|
|
||||||
component.set({ visible: true });
|
component.set({ visible: true });
|
||||||
assert.equal( global.count, 1 );
|
assert.equal( global.count, 1 );
|
||||||
const div = target.querySelector( 'div' );
|
const div = target.querySelector( 'div' );
|
||||||
assert.equal( div.foo, 0 );
|
assert.equal( div.foo, 0 );
|
||||||
|
|
||||||
now = 300;
|
raf.tick( 300 );
|
||||||
callback();
|
|
||||||
assert.equal( div.foo, 0.75 );
|
assert.equal( div.foo, 0.75 );
|
||||||
|
|
||||||
component.set({ visible: false });
|
component.set({ visible: false });
|
||||||
assert.equal( global.count, 1 );
|
assert.equal( global.count, 1 );
|
||||||
|
|
||||||
now = 500;
|
raf.tick( 500 );
|
||||||
callback();
|
|
||||||
assert.equal( div.foo, 0.25 );
|
assert.equal( div.foo, 0.25 );
|
||||||
|
|
||||||
component.set({ visible: true });
|
component.set({ visible: true });
|
||||||
now = 700;
|
raf.tick( 700 );
|
||||||
callback();
|
|
||||||
assert.equal( div.foo, 0.75 );
|
assert.equal( div.foo, 0.75 );
|
||||||
|
|
||||||
now = 800;
|
raf.tick( 800 );
|
||||||
callback();
|
|
||||||
assert.equal( div.foo, 1 );
|
assert.equal( div.foo, 1 );
|
||||||
|
|
||||||
now = 900;
|
raf.tick( 900 );
|
||||||
callback();
|
|
||||||
|
|
||||||
component.destroy();
|
component.destroy();
|
||||||
}
|
}
|
||||||
|
@ -1,61 +1,45 @@
|
|||||||
export default {
|
export default {
|
||||||
test ( assert, component, target, window ) {
|
test ( assert, component, target, window, raf ) {
|
||||||
let now = 0;
|
|
||||||
let callback;
|
|
||||||
|
|
||||||
window.performance = { now: () => now };
|
|
||||||
global.requestAnimationFrame = cb => callback = cb;
|
|
||||||
|
|
||||||
component.set({ visible: true });
|
component.set({ visible: true });
|
||||||
let div = target.querySelector( 'div' );
|
let div = target.querySelector( 'div' );
|
||||||
assert.equal( div.foo, 0 );
|
assert.equal( div.foo, 0 );
|
||||||
|
|
||||||
now = 200;
|
raf.tick( 200 );
|
||||||
callback();
|
|
||||||
assert.equal( div.foo, 0.5 );
|
assert.equal( div.foo, 0.5 );
|
||||||
|
|
||||||
now = 400;
|
raf.tick( 400 );
|
||||||
callback();
|
|
||||||
assert.equal( div.foo, 1 );
|
assert.equal( div.foo, 1 );
|
||||||
|
|
||||||
now = 500;
|
raf.tick( 500 );
|
||||||
callback();
|
|
||||||
assert.equal( div.foo, 1 );
|
assert.equal( div.foo, 1 );
|
||||||
|
|
||||||
component.set({ visible: false });
|
component.set({ visible: false });
|
||||||
now = 600;
|
raf.tick( 600 );
|
||||||
callback();
|
|
||||||
assert.equal( div.foo, 1 );
|
assert.equal( div.foo, 1 );
|
||||||
assert.equal( div.bar, 0.75 );
|
assert.equal( div.bar, 0.75 );
|
||||||
|
|
||||||
now = 900;
|
raf.tick( 900 );
|
||||||
callback();
|
|
||||||
assert.equal( div.foo, 1 );
|
assert.equal( div.foo, 1 );
|
||||||
assert.equal( div.bar, 0 );
|
assert.equal( div.bar, 0 );
|
||||||
|
|
||||||
// test outro before intro complete
|
// test outro before intro complete
|
||||||
now = 1000;
|
raf.tick( 1000 );
|
||||||
component.set({ visible: true });
|
component.set({ visible: true });
|
||||||
div = target.querySelector( 'div' );
|
div = target.querySelector( 'div' );
|
||||||
callback();
|
|
||||||
|
|
||||||
now = 1200;
|
raf.tick( 1200 );
|
||||||
callback();
|
|
||||||
assert.equal( div.foo, 0.5 );
|
assert.equal( div.foo, 0.5 );
|
||||||
|
|
||||||
component.set({ visible: false });
|
component.set({ visible: false });
|
||||||
now = 1300;
|
raf.tick( 1300 );
|
||||||
callback();
|
|
||||||
assert.equal( div.foo, 0.75 );
|
assert.equal( div.foo, 0.75 );
|
||||||
assert.equal( div.bar, 0.75 );
|
assert.equal( div.bar, 0.75 );
|
||||||
|
|
||||||
now = 1400;
|
raf.tick( 1400 );
|
||||||
callback();
|
|
||||||
assert.equal( div.foo, 1 );
|
assert.equal( div.foo, 1 );
|
||||||
assert.equal( div.bar, 0.5 );
|
assert.equal( div.bar, 0.5 );
|
||||||
|
|
||||||
now = 2000;
|
raf.tick( 2000 );
|
||||||
callback();
|
|
||||||
|
|
||||||
component.destroy();
|
component.destroy();
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,16 @@
|
|||||||
export default {
|
export default {
|
||||||
test ( assert, component, target, window ) {
|
test ( assert, component, target, window, raf ) {
|
||||||
let now = 0;
|
|
||||||
let callback;
|
|
||||||
|
|
||||||
window.performance = { now: () => now };
|
|
||||||
global.requestAnimationFrame = cb => callback = cb;
|
|
||||||
|
|
||||||
component.set({ visible: true });
|
component.set({ visible: true });
|
||||||
const div = target.querySelector( 'div' );
|
const div = target.querySelector( 'div' );
|
||||||
assert.equal( window.getComputedStyle( div ).opacity, 0 );
|
assert.equal( window.getComputedStyle( div ).opacity, 0 );
|
||||||
|
|
||||||
now = 200;
|
raf.tick( 200 );
|
||||||
callback();
|
|
||||||
assert.equal( window.getComputedStyle( div ).opacity, 0.5 );
|
assert.equal( window.getComputedStyle( div ).opacity, 0.5 );
|
||||||
|
|
||||||
now = 400;
|
raf.tick( 400 );
|
||||||
callback();
|
|
||||||
assert.equal( window.getComputedStyle( div ).opacity, 1 );
|
assert.equal( window.getComputedStyle( div ).opacity, 1 );
|
||||||
|
|
||||||
now = 500;
|
raf.tick( 500 );
|
||||||
callback();
|
|
||||||
|
|
||||||
component.destroy();
|
component.destroy();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
export default {
|
||||||
|
test ( assert, component, target, window, raf ) {
|
||||||
|
assert.equal( target.querySelector( 'div' ), component.refs.no );
|
||||||
|
assert.equal( component.refs.no.foo, 0 );
|
||||||
|
|
||||||
|
raf.tick( 200 );
|
||||||
|
assert.equal( component.refs.no.foo, 0.5 );
|
||||||
|
|
||||||
|
raf.tick( 500 );
|
||||||
|
component.set({ x: true });
|
||||||
|
assert.equal( component.refs.no, undefined );
|
||||||
|
assert.equal( component.refs.yes.foo, 0 );
|
||||||
|
|
||||||
|
raf.tick( 700 );
|
||||||
|
assert.equal( component.refs.yes.foo, 0.5 );
|
||||||
|
|
||||||
|
raf.tick( 1000 );
|
||||||
|
|
||||||
|
component.destroy();
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,20 @@
|
|||||||
|
{{#if x}}
|
||||||
|
<div ref:yes in:foo>yes</div>
|
||||||
|
{{else}}
|
||||||
|
<div ref:no in:foo>no</div>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
transitions: {
|
||||||
|
foo: function ( node, params ) {
|
||||||
|
return {
|
||||||
|
duration: 400,
|
||||||
|
tick: t => {
|
||||||
|
node.foo = t;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
Loading…
Reference in new issue