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

Requires an actual database for mock-knex to work #91

Open
dougmolineux opened this issue Aug 1, 2019 · 4 comments
Open

Requires an actual database for mock-knex to work #91

dougmolineux opened this issue Aug 1, 2019 · 4 comments
Assignees

Comments

@dougmolineux
Copy link

Thank you for this module, it's helpful to me. I am setting up my Knex object like this:

function setupDB() {
  if (process.env.NODE_ENV === 'test') {
    return Knex({ client: 'mssql' });
  }
  return Knex({
    client: 'mssql',
    connection: {
      database : process.env.DBNAME,
      host : process.env.DBHOST,
      password : process.env.DBPASS,
      user : process.env.DBUSER
    },
    useNullAsDefault: true
  });
}

I am using a local MSSQL database to test this out (ran in docker-compose), and all my tests work if the mssql database is up and running locally. My process environment variables are all configured to point to this local database.

When i run docker-compose down, stopping the container running mssql, all my tests timeout. I was hoping that when the database isn't running locally, that the mockDb would still work. Is that not correct? Am I doing something wrong here?

Thank you again.

@jbrumwell
Copy link
Owner

@dougmolineux I am able to run my tests in mysql and postgres without a db running, this may be specific to the mssql adapter in knex. What version of knex are you on?

@dougmolineux
Copy link
Author

Thank you for the response, the versions I currently have are:

    "mock-knex": "^0.4.5",
    ...
    "@types/knex": "^0.16.1",
    "knex": "0.16.5",

I could attempt to work on something that reproduces this next week if thats helpful to you, thanks again.

@jbrumwell
Copy link
Owner

@dougmolineux That would be great :)

@felixmosh
Copy link

Try knex-mock-client it works with a different approach, and it doesn't requires a real SQL server running at all.

@jbrumwell jbrumwell self-assigned this May 1, 2023
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

3 participants