Wednesday, 12 April 2017

Unit testing and mocking mySQL database in Node.js

In my Node.js API I'm connecting to a mySQL database using promise-mysql. I'm using Sequelize as ORM. I want to unit test each micro service interacting with the database.

Obviously during the tests, I don't want to create a real database connection since unit tests should not rely on dependencies like database connections. Rather I want to mock it, using either an in-memory or on-disc database like sqlite3.

I've tried migrating the SQL dump to sqlite3 but I get errors since the dump is not compatible with sqlite3. The data set is modest in size.

Can you recommend an approach?



via ChrisRich

No comments:

Post a Comment