unabridged / motion

Reactive frontend UI components for Rails in pure Ruby
https://github.com/unabridged/motion
MIT License
697 stars 19 forks source link

Add test helpers for generating events for testing #59

Closed latortuga closed 4 years ago

latortuga commented 4 years ago

I find myself wanting to test a motion that pulls data from the event and I think it would be useful if the test helpers included some new stuff:

# current API
def run_motion(component, motion)
# proposed change
def run_motion(component, motion, event = motion_event)

# does not currently exist, build a fake (or real?) Motion::Event
def motion_event(attributes = {})
  Motion::Event.new(attributes)
end

This will be useful for when you take business logic based on what's in the event object (e.g. data attributes from the DOM).