Hello there. I'll make this as short as possible. My business is using jest to run tests on a pixi project of ours, and since these are tests, all resources are replaced with empty ones. This caused an issue because certain sprites that used pixi-spine would error due to the invalid data. I instead came up with the following function:
const mockData: ISkeletonData = {
animations: [],
name: "",
bones: [],
slots: [],
skins: [],
defaultSkin: undefined,
events: [],
version: "",
hash: "",
width: 0,
height: 0,
ikConstraints: [],
transformConstraints: [],
pathConstraints: [],
findBone: function (): IBoneData { throw new Error("Function not implemented.") },
findBoneIndex: function (): number { throw new Error("Function not implemented.") },
findSlot: function (): ISlotData { throw new Error("Function not implemented.") },
findSlotIndex: function (): number { throw new Error("Function not implemented.") },
findSkin: function (): ISkin { throw new Error("Function not implemented.") },
findEvent: function (): IEventData { throw new Error("Function not implemented.") },
findAnimation: function (name) { return mockData.animations.filter(a => a.name === name)[0] },
findIkConstraint: function (): IIkConstraintData { throw new Error("Function not implemented.") },
findTransformConstraint: function (): ITransformConstraintData { throw new Error("Function not implemented.") },
findPathConstraint: function (): IPathConstraintData { throw new Error("Function not implemented.") }
}
for (const animName of animationNames) {
mockData.animations.push({
name: animName,
timelines: [],
duration: 0
})
}
return mockData
Although this works fine for creating the spineData and loading it up to a new Spine object, we came across an issue when running the setAnimation() function. What happens is that the animation will fire off the started event, but will not fire any other ones. From my observation, it is like it it isn't running at all.
My question is, how could I make a mock spineData to be used by other resources while retaining the "functionality" of a real Spine (mainly, the completed event)? Thank you for your time and help, it is truly appreciated.
Hello there. I'll make this as short as possible. My business is using jest to run tests on a
pixi
project of ours, and since these are tests, all resources are replaced with empty ones. This caused an issue because certain sprites that usedpixi-spine
would error due to the invalid data. I instead came up with the following function:This is then used like this:
Although this works fine for creating the
spineData
and loading it up to a newSpine
object, we came across an issue when running thesetAnimation()
function. What happens is that the animation will fire off thestarted
event, but will not fire any other ones. From my observation, it is like it it isn't running at all.My question is, how could I make a mock
spineData
to be used by other resources while retaining the "functionality" of a realSpine
(mainly, thecompleted
event)? Thank you for your time and help, it is truly appreciated.