mock-knex icon indicating copy to clipboard operation
mock-knex copied to clipboard

Requires an actual database for mock-knex to work

Open dougmolineux opened this issue 4 years ago • 4 comments

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.

dougmolineux avatar Aug 01 '19 17:08 dougmolineux

@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?

jbrumwell avatar Sep 06 '19 13:09 jbrumwell

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.

dougmolineux avatar Sep 06 '19 15:09 dougmolineux

@dougmolineux That would be great :)

jbrumwell avatar Sep 06 '19 21:09 jbrumwell

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

felixmosh avatar May 15 '21 14:05 felixmosh