I have an application that uses vue and express and I have tests written for each, I can run either a vue test on it's own or the express test on it's own.
Below is the jest config file this will run fine for Vue, if I remove the preset it will work fine for my supertest/express test .
module.exports = {
// TODO: This line is needed for vue tests but breaks js tests
preset: "@vue/cli-plugin-unit-jest",
coverageDirectory: "test-reports/",
coveragePathIgnorePatterns: [
"/node_modules/"
],
reporters: [
"default",
[
"jest-junit",
{
outputName: "vue_junit.xml",
outputDirectory: "test-reports/",
},
],
],
};
For reference here is both the tests if it helps
// Libraries
import Vuetify from "vuetify";
import Vue from "vue";
// Components
import UserBar from "@/components/userBar.vue"
// Utilities
import { createLocalVue, shallowMount } from "@vue/test-utils";
// Setup Up
const localVue = createLocalVue();
const vuetify = new Vuetify();
Vue.use(Vuetify);
describe("userBar.vue", () => {
let wrapper;
beforeEach(() => {
wrapper = shallowMount(UserBar, {
localVue,
vuetify,
});
});
afterEach(() => {
wrapper.destroy();
});
it("wrapper created properly", () => {
expect(typeof wrapper).toBe("object");
});
});
express test
var request = require('supertest');
import * as local from '../../server';
var express = require('express');
var app = express();
describe('loading express', function () {
var server;
beforeEach(function () {
delete require.cache[require.resolve('../../server/index')];
server = local.default(app);
});
afterEach(function (done) {
server.close(done);
});
it('responds to /client', function testSlashHealth(done) {
request(server)
.get('/client')
.expect(200, done);
});
it('404 everything else', function testPath(done) {
request(server)
.get('/foo/bar')
.expect(404, done);
});
});
Got around this by specifying 2 config files when testing
jest -c jest.config.express.js
jest -c jest.config.vue.js