Skip to content

v0.6.3

Compare
Choose a tag to compare
@zalmoxisus zalmoxisus released this 16 Aug 08:03
· 155 commits to master since this release

Autogenerate "real" tests

As announced at React Europe, remotedev-app can generate tests for the inspected actions.

Thanks to Redux principles, it's a rather simple task:

expect(reducer(pervousState, action), currentState);

However, such tests are difficult to maintain and they aren't human-readable. Hacking a lot these days, we can now check only what was changed.

So, instead of

expect(
  reducers(
    {counter:0},
    {type:'INCREMENT_COUNTER'}
  )
).toEqual(
  {counter:1}
);

the extension generates tests like so

state = reducers(
  {counter:0},
  {type:'INCREMENT_COUNTER'}
);
expect(state.counter).toEqual(1);

Or for arrays, instead of

expect(
  reducers(
    {todos:[{text:'Use Redux',completed:false,id:0}]},
    {type:'ADD_TODO',text:'Generate tests'})
  )
).toEqual(
  {todos:[{id:1,completed:false,text:'Generate tests'},{text:'Use Redux',completed:false,id:0}]}
);

it will check only the length and new elements:

state = reducers(
  {todos:[{text:'Use Redux',completed:false,id:0}]},
  {type:'ADD_TODO',text:'Generate tests'})
);
expect(state.todos.length).toEqual(2);
expect(state.todos[0]).toEqual({id:1,completed:false,text:'Generate tests'});

Here's the full autogenerated test with also changing and removing an item:
screen shot 2016-08-14 at 5 00 16 pm