Skip to content

Commit

Permalink
add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jul 16, 2024
1 parent 02b9723 commit dc6d9e2
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { test } from '../../test';

export default test({
get props() {
return { visible: false };
},

test({ assert, component, target, raf, logs }) {
component.visible = true;
const span = /** @type {HTMLSpanElement & { foo: number }} */ (target.querySelector('span'));

raf.tick(50);
assert.equal(span.foo, 0.5);

component.visible = false;
assert.equal(span.foo, 0.5);

raf.tick(75);
assert.equal(span.foo, 0.25);

component.visible = true;
raf.tick(100);
assert.equal(span.foo, 0.5);

assert.deepEqual(logs, ['transition']); // should only run once
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script>
export let visible;
function foo(node) {
console.log('transition');
return {
duration: 100,
tick: (t) => {
node.foo = t;
}
};
}
</script>

{#if visible}
<span transition:foo>hello</span>
{/if}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { test } from '../../test';

export default test({
get props() {
return { visible: false };
},

test({ assert, component, target, raf, logs }) {
component.visible = true;
const span = /** @type {HTMLSpanElement & { foo: number, bar: number }} */ (
target.querySelector('span')
);

raf.tick(50);
assert.equal(span.foo, 0.5);

component.visible = false;
assert.equal(span.foo, 0.5);

raf.tick(75);
assert.equal(span.foo, 0.75);
assert.equal(span.bar, 0.75);

component.visible = true;
raf.tick(100);
assert.equal(span.foo, 0.25);
assert.equal(span.bar, 1);

assert.deepEqual(logs, ['in', 'out', 'in']);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<script>
export let visible;
function foo(node) {
console.log('in');
return {
duration: 100,
tick: (t) => {
node.foo = t;
}
};
}
function bar(node) {
console.log('out');
return {
duration: 100,
tick: (t) => {
node.bar = t;
}
};
}
</script>

{#if visible}
<span in:foo out:bar>hello</span>
{/if}

0 comments on commit dc6d9e2

Please sign in to comment.