January 2018
Beginner
658 pages
13h 10m
English
Now, the way that rewire works is it requires you to use rewire instead of require when you're loading in the file that you want to mock out. For this example, we want to replace db with something else, so when we load an app we have to load it in in a special way. We'll make a variable called app, and we'll set it equal to rewire followed by what we would usually put inside of require. In this case it's a relative file, a file that we created ./app will get the job done:
const expect = require('expect');const rewire = require('rewire');var app = rewire('./app');
Now rewire loads your file through require, but it also adds two methods onto app. These methods are:
We can use these to mock ...
Read now
Unlock full access