-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: transition
onComplete
triggers after each property animation (#…
…189)
- Loading branch information
1 parent
5e2346a
commit e0dec92
Showing
6 changed files
with
137 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { type Mock, vi } from 'vitest' | ||
import { h } from 'vue' | ||
import { MotionComponent } from '../../src/components' | ||
|
||
export function useCompletionFn() { | ||
return vi.fn(() => {}) | ||
} | ||
|
||
// Get component using either `v-motion` directive or `<Motion>` component | ||
export function getTestComponent(t: string) { | ||
if (t === 'directive') { | ||
return { template: `<div v-motion>Hello world</div>` } | ||
} | ||
|
||
return { render: () => h(MotionComponent) } | ||
} | ||
|
||
// Waits until mock has been called and resets the call count | ||
export async function waitForMockCalls(fn: Mock, calls = 1, options: Parameters<typeof vi.waitUntil>['1'] = { interval: 10 }) { | ||
try { | ||
await vi.waitUntil(() => fn.mock.calls.length === calls, options) | ||
fn.mockReset() | ||
} catch (err) { | ||
// This ensures the vitest error log shows where this helper is called instead of the helper internals | ||
if (err instanceof Error) { | ||
err.message += ` Waited for ${calls} call(s) but failed at ${fn.mock.calls.length} call(s).` | ||
|
||
const arr = err.stack?.split('\n') | ||
arr?.splice(0, 3) | ||
err.stack = arr?.join('\n') ?? undefined | ||
} | ||
throw err | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// adapted from https://github.com/thebuilder/react-intersection-observer/blob/d35365990136bfbc99ce112270e5ff232cf45f7f/src/test-helper.ts | ||
// and https://jaketrent.com/post/test-intersection-observer-react/ | ||
import { afterEach, beforeEach, vi } from 'vitest' | ||
|
||
const observerMap = new Map() | ||
const instanceMap = new Map() | ||
|
||
beforeEach(() => { | ||
// @ts-expect-error mocked | ||
window.IntersectionObserver = vi.fn((cb, options = {}) => { | ||
const instance = { | ||
thresholds: Array.isArray(options.threshold) ? options.threshold : [options.threshold], | ||
root: options.root, | ||
rootMargin: options.rootMargin, | ||
observe: vi.fn((element: Element) => { | ||
instanceMap.set(element, instance) | ||
observerMap.set(element, cb) | ||
}), | ||
unobserve: vi.fn((element: Element) => { | ||
instanceMap.delete(element) | ||
observerMap.delete(element) | ||
}), | ||
disconnect: vi.fn(), | ||
} | ||
return instance | ||
}) | ||
}) | ||
|
||
afterEach(() => { | ||
// @ts-expect-error mocked | ||
window.IntersectionObserver.mockReset() | ||
instanceMap.clear() | ||
observerMap.clear() | ||
}) | ||
|
||
export function intersect(element: Element, isIntersecting: boolean) { | ||
const cb = observerMap.get(element) | ||
if (cb) { | ||
cb([ | ||
{ | ||
isIntersecting, | ||
target: element, | ||
intersectionRatio: isIntersecting ? 1 : -1, | ||
}, | ||
]) | ||
} | ||
} | ||
|
||
export function getObserverOf(element: Element): IntersectionObserver { | ||
return instanceMap.get(element) | ||
} |