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

Mocks in the unit test suite do not work when you use more than one method in the same test. #29

Open
jhomarolo opened this issue Oct 11, 2021 · 0 comments
Labels
bug Something isn't working hacktoberfest ready-to-work Item is ready to work on it severity-minor Item is not urgent

Comments

@jhomarolo
Copy link
Contributor

Describe the bug
Mocks in the unit test suite do not work when you use more than one method in the same test.
Example: If you want to test in a method the limit with orderBy or where with offset, won't work.

To Reproduce
Steps to reproduce the behavior:

  1. Go to find suite test, and let's check the should return entities with column order by method:
    it('should return entities with collumn order by', async () => {
  2. If you add a limit clause into this method, like this:
//when
const ret = await itemRepo.find({ limit: 1,  orderBy: 'stringTest' })
  1. Then the test will break showing about the query.orderBy is not a function

Expected behavior
I expect that multiple causes in the test runner cases work's fine together

Additional context
I believe that the problem is because how the methods works overriding the knex(mock) instance to join multiple conditions in the same query.

    if (options.limit > 0) query = query.limit(options.limit)
    if (options.offset > 0) query = query.offset(options.offset)

See the find method in the image:
image

When the query var, receives a new query instance, the order methods that was inside the knex instance, no longer exists

image

@jhomarolo jhomarolo added the bug Something isn't working label Oct 11, 2021
@jhomarolo jhomarolo added ready-to-work Item is ready to work on it severity-minor Item is not urgent labels Dec 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hacktoberfest ready-to-work Item is ready to work on it severity-minor Item is not urgent
Projects
None yet
Development

No branches or pull requests

2 participants