Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lets change the API for spyLifecycle and spyMethods #26

Closed
goatslacker opened this issue Nov 16, 2015 · 5 comments
Closed

Lets change the API for spyLifecycle and spyMethods #26

goatslacker opened this issue Nov 16, 2015 · 5 comments

Comments

@goatslacker
Copy link
Contributor

The goal of this is to

  • Make whats happening a bit more explicit. Currently there's a bit of magic.
  • Let you use your own sinon rather than rely on reagent using its own.
let spy; 

describe('MyComponent', () => {
  beforeEach() {
    spy = reagent.spyLifecycle(sinon, MyComponent);
  },

  it('should do things', () => {
    const my = mount(<MyComponent />);
    my.setProps({ hello: 'world' });

    assert.isTrue(spy.get('componentWillReceiveProps').calledOnce, 'receive props was called');

    // or if we don't want to be stringly typed...
    assert.isTrue(my.componentWillReceiveProps.calledOnce);
  });

  afterEach() {
    spy.destroy();
  }
});

Pros: It's more explicit what's happening.
Cons: You now have to do the beforeEach/afterEach setup yourself.

Ideally we'd merge spyLifecycle and spyMethods so it just spies every method.

@lelandrichardson
Copy link
Collaborator

the spies would attach themselves to the prototype, so you would be able to retrieve them from: MyComponent.prototype.componentWillReceiveProps.calledOnce

@goatslacker
Copy link
Contributor Author

Right on but that's ugly and verbose. I'd rather peep the instance instead.

@lelandrichardson
Copy link
Collaborator

lol... so you want to make the spying way more verbose, but then you complain about typing out .prototype? :)

also the my.componentWillReceiveProps.calledOnce won't work. We'd need to do my.instance().componentWillReceiveProps.calledOnce right now unless we added something to the ReactWrapper prototype

@goatslacker
Copy link
Contributor Author

Yes. :)

I'd love to have my 🍰 and eat it too by having a not verbose explicit spy.

@lelandrichardson
Copy link
Collaborator

Closing as these APIs no longer exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants