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

Add failing test showing that this library does not work with res.write/res.end #21

Merged
merged 4 commits into from
Dec 20, 2018

Conversation

magicmark
Copy link
Contributor

turns out this library doesn't work when apps call res.write / res.end 😬

I've added a failing test (with a .skip) that demonstrates this flaw.

╔═ markl@dev21-uswest1cdevc: ~/GitApps/tweenz git:(add_failing_test) ✗ virtualenv:(venv)
╚═ ♪ yarn test --no-watchman
yarn run v1.12.1
$ jest --coverage --no-watchman
 FAIL  __tests__/index.test.js
  middleware
    ✓ should work with res.json (38ms)
    ✓ should work with res.send (5ms)
    ✓ should work with res.send (json) (3ms)
    ✕ should work with res.end (11ms)

  ● middleware › should work with res.end

    expect(jest.fn()).toHaveBeenCalledWith(expected)

    Expected mock function to have been called with:
      "foobarbaz"
    as argument 1, but it was called with
      undefined.

    Difference:

      Comparing two different types of values. Expected string but received undefined.

      79 |             .end(() => {
      80 |                 expect(beforeFn).toHaveBeenCalled();
    > 81 |                 expect(afterFn).toHaveBeenCalledWith('foobarbaz');
         |                                 ^
      82 |                 done();
      83 |             });
      84 |     });

      at Test.toHaveBeenCalledWith (__tests__/index.test.js:81:33)
      at Test.Object.<anonymous>.Test.assert (node_modules/supertest/lib/test.js:181:6)
      at Server.localAssert (node_modules/supertest/lib/test.js:131:12)

----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |      100 |      100 |      100 |      100 |                   |
 index.js |      100 |      100 |      100 |      100 |                   |
----------|----------|----------|----------|----------|-------------------|
Test Suites: 1 failed, 1 total
Tests:       1 failed, 3 passed, 4 total
Snapshots:   0 total
Time:        1.415s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Let's fix this :P

@magicmark magicmark changed the title Add failing test Add failing test showing that this library does not work with res.write/res.end Dec 19, 2018
Copy link
Member

@mxmul mxmul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lg2m!

@magicmark magicmark merged commit 76f2559 into master Dec 20, 2018
@magicmark magicmark deleted the add_failing_test branch December 20, 2018 00:10
magicmark added a commit that referenced this pull request Dec 20, 2018
magicmark added a commit that referenced this pull request Dec 24, 2018
magicmark added a commit that referenced this pull request Dec 24, 2018
magicmark added a commit that referenced this pull request Jan 16, 2019
Fix #21 (intercept res.write / res.end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants