fakeServer.respond(); not working... #1130

Open
funyapu opened this Issue Aug 18, 2016 · 2 comments

Projects

None yet

3 participants

@funyapu
funyapu commented Aug 18, 2016 edited

Sorry, but currently have no time to create a sample project...
Will do it on weekend if needed.

karma@0.13.22
mocha@2.5.3
phantomjs@2.1.1
jsdom@7.2.2
react@15.3.0
react-addons-test-utils@15.3.0
redux@3.5.2

What did you expect to happen?

  1. Switch a <Td /> to <Input type="text"/> by clicking.
  2. POST a data by keyPress Enter in the <Input>.
  3. Update redux reducer(data store) on response.
  4. Flash DOM and the <Input /> should change to <TD />.

What actually happens

  • Test result
Error: Expected 'INPUT' to be 'TD' (test.spec.js:3485 <- webpack:///~/expect/lib/assert.js?3e24:24:0)
  • Error Log
ERROR LOG: 'Unhandled promise rejection', TypeError{stack:~~~

How to reproduce

Will write later. Should be like below....

  1. Create a React page w/ <Table />.
  2. Write a function to switch the <TD /> to <Input type="text" /> by clicking.
  3. Write a function to post data by key press on enter in <Input />.
  4. Test case will be like berow:
  it('edit nickname', (done) => {

    fakeServer.respondWith('POST', '/post_url',
      [
        200,
        {'Content-Type': 'application/json'},
        JSON.stringify({
          nickname: 'edited'
        })
      ]
    );

    let getNicknameNode = () => TestUtils.findRenderedDOMComponentWithClass(component, 'nickname');

    // Switch the td to input
    TestUtils.Simulate.doubleClick(getNicknameNode());
    expect(getNicknameNode().nodeName).toBe('INPUT');

    // Change the value and POST it.
    getNicknameNode().value = 'ts';
    TestUtils.Simulate.change(getNicknameNode());
    TestUtils.Simulate.keyPress(getNicknameNode(), {key: "Enter", keyCode: 13, which: 13});
    fakeServer.respond();

    setTimeout(
      () => {
        expect(getNicknameNode().nodeName).toBe('TD');
        expect(getNicknameNode().textContent).toBe('ts');
        done();
      },
      10
    );
  });
@fatso83
Contributor
fatso83 commented Aug 18, 2016

This is clearly not a sufficient test case to prove that anything is wrong with Sinon. Your test error could be from any number of reasons, including errors in your React component. If you want to demonstrate an actual error in Sinon, please rid your test case of React specifics as there is no way of knowing if this is Sinon's fault or something else from the test case.

What is interesting is that you say this does not happen with Sinon 1.17.4. If you can provide us with any complete, runnable code that fails in 1.17.5 but not in 1.17.4, please do.

@droarty
droarty commented Sep 23, 2016

I had a similarly weird issue when updating to 1.17.5. Rolling back to 1.17.4 fixed it.

I couldn't pin point sinon as the issue though. My specs fail due to then never being called in $.ajax({..}).then(). Where I used the ajax success: callback I didn't have problems. My problem in isolating this is in that I am also migrating React from 15.2.1 to 15.3.1. If I only update one of these two packages and not the other I don't get the problem. If I update both, I get the problem. Sorry I don't have time to dig in deeper, but thought I would share. Btw, in case it is relevant, I use jQuery 3.x and the respondImediately flag.

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