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

Test matches passes when the files are't the same #13

Closed
arszh opened this issue Nov 29, 2019 · 5 comments
Closed

Test matches passes when the files are't the same #13

arszh opened this issue Nov 29, 2019 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@arszh
Copy link
Contributor

arszh commented Nov 29, 2019

Test "Creating an Excel file from form matches previous sample file'"passes when the files are't the same , because expect inside 'try/catch'. Jest has issue #3917 about this problem.

There is also a problem that the actual file from "sample.xlsx" and the exported file have different sizes.

actual value to equal:
  7793
expected:
  7823

Expected Behavior

if a actual and a expected files have different sizes then test fails

Current Behavior

Test always passes.

Possible Solution

  1. Remove "try/catch" because it also prevents find errors and situations where exceptions are raised.
  2. Use cvle's gist

Steps to Reproduce (for bugs)

  1. change expected.size or actual.size to any number
  2. run test
  3. test passed

Context

I met this problem when worked on #12

Your Environment

  • Library Version used: 1.0.6
  • Node.js version (e.g. Node.js 5.4): v12.13.1
  • Operating System and version (desktop or mobile): macOS Catalina 10.15.1
@lirantal lirantal self-assigned this Nov 29, 2019
@lirantal
Copy link
Owner

Oh I see. That's a good catch @arszh
Not sure how I feel about that gist workaround, doesn't seem friendly. What if we just refactor the test a bit so that the expect is simply not inside a try/catch?

@lirantal lirantal added the bug Something isn't working label Nov 29, 2019
@arszh
Copy link
Contributor Author

arszh commented Dec 1, 2019

We can declare actual and expected variables before try/catch and move down expect(expected.size).toEqual(actual.size) under try/catch, but I think it is not good.

In my opinion, maybe I wrong, we can delete the try/catch altogether because:

  1. It prevents find errors and situations where exceptions are raised.
  2. Test doesn't check receiving certain exceptions.
  3. 'Catch' doesn't improve information from caught exception to output it.

If important to remove created file after this test:

  1. It will be deleted anyway when developer fix fail and the test is passed.
  2. Can use afterAll() to remove all created excel files after all tests.

@lirantal
Copy link
Owner

lirantal commented Dec 1, 2019

this is the test we're referring to, right?

    try {
      // eslint-disable-next-line
      const actual = fs.statSync(path.resolve('./__tests__/Fixtures/sample.xlsx'))
      // eslint-disable-next-line
      const expected = fs.statSync(path.resolve(testOutputFilename))

      expect(expected.size).toEqual(actual.size)
    } catch (e) {
    } finally {
      // eslint-disable-next-line
      fs.unlinkSync(testOutputFilename)
    }

in which case, the expectation is within a try/catch only for the sake of cleaning-up. In this case, how about we simply clean up in a Jest's afterAll() hook? Surely it's not as clean as with doing this within every test, but for the sake of this small lib seems not far fetched.

Looks like you are suggesting the same so 👍 from me and I'm happy to merge a PR if you have a bit of time to send it over.

arszh added a commit to arszh/typeform-export-excel that referenced this issue Dec 16, 2019
sizes of correct created excel file  and old sample  were not the same

lirantal#13
arszh added a commit to arszh/typeform-export-excel that referenced this issue Dec 16, 2019
remove try/catch and add afterall

fix lirantal#13
@arszh arszh mentioned this issue Dec 16, 2019
8 tasks
@lirantal
Copy link
Owner

fixed in #18

@Harshu53
Copy link

Harshu53 commented Feb 5, 2020

@arszh @lirantal Can you guys please suggest what should be fixed for below case, It is always passing :

test("test", () => {
  try {
    expect(true).toBe(false);
  } catch (err) {
    console.log(err);
  }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants