16 createstub - ranhs/soda-test GitHub Wiki
In some cases, you need to test a library that makes calls in the model body to other library, that you don't want your test to realy access. For example in app.ts there is a connection to mongoose database:
import { connect } from 'mongoose'
import { getURL } from '../config/database'
connect(getURL())
The above code alls the connect method of mongoose. In your test environment you don't have mongoose database, and you don't want to access mongoose databasebase. If you load the app.ts modle, it will try to connect to mongoose database and fail. What you ready want to do is to stub the create method, but not when running a specific test-step, but rater when loading the app.ts model.
Soda-Test gives you a method called createStub that will create a stub when called. You need to call it before importing the app model, and call restore after the call:
const connectStub: SinonStub = createStub('mongoose', 'connect').returns(null)
import { app } from './app'
connectStub.restore()
This will stub to call to connect on mongoose by the app.ts model, will still define the routes so you could be tested using supertest