Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

Builder: updated unit test handling non-existent resume

gianantoniopini9a7bdb188b01
diff --git a/__mocks__/gatsby-plugin-firebase/auth/auth.js b/__mocks__/gatsby-plugin-firebase/auth/auth.js
index b27aaf102..fc5eb043b 100644
--- a/__mocks__/gatsby-plugin-firebase/auth/auth.js
+++ b/__mocks__/gatsby-plugin-firebase/auth/auth.js
@@ -2,7 +2,7 @@
import { v4 as uuidv4 } from 'uuid';
import Constants from '../constants/auth';
-import delay from '../utils/index';
+import delay from '../../utils/index';
const singleton = Symbol('');
const singletonEnforcer = Symbol('');
diff --git a/__mocks__/gatsby-plugin-firebase/database/reference.js b/__mocks__/gatsby-plugin-firebase/database/reference.js
index 305c82b78..08e345fdb 100644
--- a/__mocks__/gatsby-plugin-firebase/database/reference.js
+++ b/__mocks__/gatsby-plugin-firebase/database/reference.js
@@ -3,7 +3,7 @@ import { v4 as uuidv4 } from 'uuid';
import DatabaseConstants from '../constants/database';
import DataSnapshot from './dataSnapshot';
-import delay from '../utils/index';
+import delay from '../../utils/index';
const parsePath = (path) => {
if (!path) {
diff --git a/__mocks__/gatsby.js b/__mocks__/gatsby.js
index e9339f5d9..09ea71c73 100644
--- a/__mocks__/gatsby.js
+++ b/__mocks__/gatsby.js
@@ -1,5 +1,7 @@
import React from 'react';
+import delay from './utils/index';
+
const Gatsby = jest.requireActual('gatsby');
const fluidImageShapes = [
@@ -67,6 +69,14 @@ const useStaticQuery = () => ({
},
});
+const defaultDelayInMilliseconds = 100;
+
+const navigate = async () => {
+ await delay(defaultDelayInMilliseconds);
+
+ return Promise.resolve();
+};
+
module.exports = {
...Gatsby,
graphql: jest.fn(),
@@ -76,6 +86,6 @@ module.exports = {
href: to,
}),
),
- navigate: jest.fn(),
+ navigate: jest.fn(navigate),
useStaticQuery,
};
diff --git a/__mocks__/gatsby-plugin-firebase/utils/index.js b/__mocks__/utils/index.js
similarity index 100%
rename from __mocks__/gatsby-plugin-firebase/utils/index.js
rename to __mocks__/utils/index.js
diff --git a/src/pages/app/__tests__/builder.test.js b/src/pages/app/__tests__/builder.test.js
index 558609357..cc9b80ef0 100644
--- a/src/pages/app/__tests__/builder.test.js
+++ b/src/pages/app/__tests__/builder.test.js
@@ -89,15 +89,27 @@ describe('Builder', () => {
describe('handles errors', () => {
describe('if resume does not exist', () => {
+ const waitForNavigateFunctionToHaveCompleted = async () => {
+ await waitFor(() => mockNavigateFunction.mock.results[0].value);
+ };
+
beforeEach(async () => {
await setup('xxxxxx', false, false);
});
- it('navigates to Dashboard', async () => {
+ afterEach(async () => {
+ await waitForNavigateFunctionToHaveCompleted();
+ });
+
+ it('navigates to Dashboard and displays notification', async () => {
await waitFor(() =>
expect(mockNavigateFunction).toHaveBeenCalledTimes(1),
);
expect(mockNavigateFunction).toHaveBeenCalledWith('/app/dashboard');
+
+ await waitFor(() => {
+ expect(screen.getByRole('alert')).toBeInTheDocument();
+ });
});
});
});