Skip to content

component testing #106

Open
Open
@catmando

Description

@catmando

Need some way to test components.

Right now no reason why capybara will not work, but that is for testing entire view (or component tree), but we should have a way to "unit test" individual components.

What we need is a way to test an individual component through a set of lifecycle changes (i.e. new params, or events) and then see what the final result is.

Like this

    MyComponent.test do |c|  
      c.mount(...)           # mount component and send parameters
      c.send_event(...)  # send event...
      c.wait(...)              # simulate elapsed time
      c.update(...)         # send new parameters
    end.will_render do 
     div { SomeAppComponent(p1: ... p2 ...) } }  
    end

How..???

test should be straight forward - it makes a dummy component that responds to mount, send_event, etc. Each of these just updates state in the dummy component / uses react event test harness, to rerender MyComponent.... The whole thing returns an object that responds to will_render, which will just dump out the dummy_components DOM.

Meanwhile some monkey patching needed so that all Application components just render "themselves" (i.e. SomeAppComponent(p1: ... p2: ...) renders <SomeAppComponent params: "...">

Finally will_render is set up so that it renders the block to a static string, such that the string should be an exact match.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions