I can't seem to get Jest to mock my dependencies.
package.json:
{
...
"scripts": {
"start": "webpack && concurrently --kill-others 'webpack --watch' 'nodemon build/server.js'",
"test": "jest"
},
"author": "Jonathan Conway",
"license": "ISC",
"devDependencies": {
"babel-jest": "^15.0.0",
"babel-polyfill": "^6.13.0",
"jest": "^15.1.1",
"jest-cli": "^15.1.1"
},
...
"jest": {
"scriptPreprocessor": "jest-script-preprocessor.js",
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(es6|js|json)$"
}
}
src/app.js:
import express from 'express';
let app = express();
app.set('view engine', 'ejs');
app.set('views', '');
app.use('/build/public', express.static('build/public'));
export default app;
src/components/home/home.routes.js:
import app from '../../app';
export default class HomeRoutes {
constructor () {
app.get('/', (req, res) => {
res.render('src/components/home/home');
});
}
}
src/components/home/home.test.js:
jest.mock('../../app');
const app = require('../../app');
const HomeRoutes = require('./home.routes');
it('works', () => {
app.get = jest.genMockFunction();
var homeRoutesInstance = new HomeRoutes.default();
console.log(app.get.mock.calls.length); // outputs 0
});
When I run npm test on this, I gete 0 calls on the app.get function, despite the HomeRoutes constructor calling app.get.
Am I missing something here? Perhaps some extra configuration of Jest is required?
Thanks!
Aucun commentaire:
Enregistrer un commentaire