Skip to content

Feature Request: test utils for animations #92

@mauro1855

Description

@mauro1855

Hi,
Recently I was writing some tests to check if my animations were correctly triggered when, for example, I press a button or when I navigate away or wtv other use case I had.

I created a couple of functions to help me with this, which to be honest I'm not sure are strictly correct since I had to dig around in the methods / props available for a Lightning component instance. I wrote this:

export function getAnimations(Element) {
  return Array.from(Element.stage.animations.active).filter(
    a => a._element === Element || a._settings._actions.some(e => e._selector === Element.__ref)
  )
}

export function isAnimatingProp(Element, property) {
  const animations = getAnimations(Element)
  return animations.some(e => {
    if (e._element === Element) {
      return e._settings._actions.some(a => a._props[0] === property)
    } else {
      return e._settings._actions.some(
        a => a._selector === Element.__ref && a._props[0] === property
      )
    }
  })
}

I was wondering if you want to include these methods in the test-utils. Feel free to modify them if you think they are not correct.

Here is an example of a test making use of these:

test('moreInfo signal from Controls triggers controls and more info animations', async () => {
    const { instance } = await renderComponent(mockedStation, mockedVideoRecording)
    instance.PlayerControls.signal('moreInfo')

    expect(isAnimatingProp(instance.PlayerControls, 'y')).toBeTruthy()
    expect(isAnimatingProp(instance.MoreInfo, 'x')).toBeTruthy()
  })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions