Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @jest-environment node
*/
import { animateTarget } from "../visual-element-target"

describe("animateTarget in a non-browser environment", () => {
const createValue = () => ({
get: () => 0,
set: () => {},
isAnimating: () => false,
start: () => {},
stop: () => {},
animation: undefined,
})

const createVisualElement = () => {
const values: Record<string, any> = {}
return {
getDefaultTransition: () => undefined,
animationState: undefined,
latestValues: {},
shouldReduceMotion: false,
props: {},
getValue: (key: string) => {
if (key === "willChange") return undefined
return (values[key] ||= createValue())
},
addValue: () => {},
} as any
}

it("does not throw when window is undefined", () => {
expect(typeof window).toBe("undefined")
expect(() =>
animateTarget(createVisualElement(), { opacity: 1 })
).not.toThrow()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import type { TargetAndTransition } from "../../node/types"
import type { AnimationTypeState } from "../../render/utils/animation-state"
import type { VisualElement } from "../../render/VisualElement"

const isBrowser = typeof window !== "undefined"

/**
* Decide whether we should block this animation. Previously, we achieved this
* just by checking whether the key was listed in protectedKeys, but this
Expand Down Expand Up @@ -114,7 +116,7 @@ export function animateTarget(
* to see if we're handling off from an existing animation.
*/
let isHandoff = false
if (window.MotionHandoffAnimation) {
if (isBrowser && window.MotionHandoffAnimation) {
const appearId = getOptimisedAppearId(visualElement)

if (appearId) {
Expand Down