Skip to content
This repository has been archived by the owner on Jun 6, 2022. It is now read-only.

Commit

Permalink
contrib/src/lib/customAxios: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Mar 13, 2019
1 parent 0724cbb commit c5e2be0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
6 changes: 6 additions & 0 deletions packages/contrib/__mocks__/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
serverRuntimeConfig: {},
publicRuntimeConfig: {
API_URI: "http://localhost:3200"
}
};
6 changes: 6 additions & 0 deletions packages/contrib/__tests__/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { setConfig } from "next/config";

// https://github.com/zeit/next.js/issues/4024#issuecomment-386016077
// TODO Wait for release of: https://github.com/zeit/next.js/pull/6458.
import nextConfig from "../__mocks__/next.config";
setConfig(nextConfig);
16 changes: 16 additions & 0 deletions packages/contrib/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
collectCoverageFrom: ["<rootDir>/pages/**/*.js", "<rootDir>/src/**/*.js"],
moduleNameMapper: {
"\\.(jpg|jpeg|png|gif|eot|svg|ttf|woff|woff2)$":
"<rootDir>/__mocks__/fileTransformer.js",
"\\.css$": "identity-obj-proxy"
},
modulePathIgnorePatterns: [
"<rootDir>/__tests__/",
"<rootDir>/.next/",
"<rootDir>/node_modules/",
"<rootDir>/package.json",
"<rootDir>/yarn.lock"
],
setupFiles: ["<rootDir>/__tests__/jest.setup.js"]
};
16 changes: 0 additions & 16 deletions packages/contrib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,5 @@
"url-loader": "^1.1.2",
"webpack-merge": "^4.2.1"
},
"jest": {
"collectCoverageFrom": [
"pages/**/*.js",
"src/**/*.js"
],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|svg|ttf|woff|woff2)$": "<rootDir>/__mocks__/fileTransformer.js",
"\\.css$": "identity-obj-proxy"
},
"modulePathIgnorePatterns": [
"<rootDir>/.next/",
"<rootDir>/node_modules/",
"<rootDir>/package.json",
"<rootDir>/yarn.lock"
]
},
"license": "Apache-2.0"
}
4 changes: 2 additions & 2 deletions packages/contrib/src/lib/__tests__/customAxios.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import "../../../__mocks__/sessionStorage";
import customAxios from "../customAxios";

// TODO Find a way to test the interceptor?
describe("[Contrib] lib/customAxios()", () => {
describe.only("[Contrib] lib/customAxios()", () => {
let _axios;
const token = "aFakeToken";

// eslint-disable-next-line max-len
it("should set the axios instance as expected with no JWT in session", async () => {
_axios = customAxios();

expect(_axios.defaults.headers["Authorization"]).toBe("Bearer null");
expect(_axios.defaults.headers["Authorization"]).toBe(undefined);
expect(_axios.defaults.baseURL).toBe("http://localhost:3200");
expect(sessionStorage.getItem("jwt")).toBe(null);
});
Expand Down

0 comments on commit c5e2be0

Please sign in to comment.