mirror of
https://github.com/BradNut/weddingsite
synced 2025-09-08 17:40:36 +00:00
Adding jest setup and basic tests.
This commit is contained in:
parent
9cef886e31
commit
115f470c4d
9 changed files with 115 additions and 2 deletions
2
.jest/setEnvVars.js
Normal file
2
.jest/setEnvVars.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
process.env.PUBLIC_CLOUD_NAME='testCloudName';
|
||||
process.env.PUBLIC_FOLDER_NAME='testFolderName';
|
||||
8
__tests__/Home.test.js
Normal file
8
__tests__/Home.test.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { render, screen } from '@testing-library/react';
|
||||
import HomePage from '../pages';
|
||||
|
||||
describe('Index Page <HomePage />', () => {
|
||||
it('should render', () => {
|
||||
render(<HomePage />);
|
||||
});
|
||||
});
|
||||
15
__tests__/Nav.test.js
Normal file
15
__tests__/Nav.test.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { render, screen } from '@testing-library/react';
|
||||
import Nav from '../components/Nav';
|
||||
|
||||
const useRouter = jest.spyOn(require('next/router'), 'useRouter');
|
||||
|
||||
describe('<Nav/>', () => {
|
||||
it('Renders nav correctly and matches snapshot', () => {
|
||||
const router = { pathname: '/' };
|
||||
useRouter.mockReturnValue(router);
|
||||
const { container, debug } = render(<Nav />);
|
||||
expect(container).toMatchSnapshot();
|
||||
const link = screen.getByText('RSVP');
|
||||
expect(link).toHaveAttribute('href', '/rsvp');
|
||||
});
|
||||
});
|
||||
46
__tests__/__snapshots__/Nav.test.js.snap
Normal file
46
__tests__/__snapshots__/Nav.test.js.snap
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`<Nav/> Renders nav correctly and matches snapshot 1`] = `
|
||||
<div>
|
||||
<nav
|
||||
class="NavStyles-sc-vewc8g-0 dWZdml"
|
||||
>
|
||||
<a
|
||||
aria-current="page"
|
||||
href="/"
|
||||
>
|
||||
Home
|
||||
</a>
|
||||
<a
|
||||
href="/story"
|
||||
>
|
||||
Our Story
|
||||
</a>
|
||||
<a
|
||||
href="/party"
|
||||
>
|
||||
Wedding Party
|
||||
</a>
|
||||
<a
|
||||
href="/photos"
|
||||
>
|
||||
Photos
|
||||
</a>
|
||||
<a
|
||||
href="/travelstay"
|
||||
>
|
||||
Travel & Stay
|
||||
</a>
|
||||
<a
|
||||
href="/qanda"
|
||||
>
|
||||
Q + A
|
||||
</a>
|
||||
<a
|
||||
href="/rsvp"
|
||||
>
|
||||
RSVP
|
||||
</a>
|
||||
</nav>
|
||||
</div>
|
||||
`;
|
||||
22
__tests__/buildBase64Data.test.js
Normal file
22
__tests__/buildBase64Data.test.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import buildBase64Data from '../utils/buildBase64Data';
|
||||
|
||||
describe('build base 64 function', () => {
|
||||
const imageName = 'https://picsum.photos/1307/880';
|
||||
const alt = 'test alt';
|
||||
it('takes an image name and builds base64 image', async () => {
|
||||
const imageData = await buildBase64Data(false, imageName, alt, {});
|
||||
expect(imageData).toBeDefined();
|
||||
expect(imageData.alt).toEqual(alt);
|
||||
expect(imageData.imageProps).toBeDefined();
|
||||
expect(imageData.imageProps.blurDataURL).toContain(
|
||||
'data:image/jpeg;base64'
|
||||
);
|
||||
expect(imageData.imageProps.height).toBeGreaterThan(0);
|
||||
expect(imageData.imageProps.width).toBeGreaterThan(0);
|
||||
expect(imageData.imageProps.src).toContain(imageName);
|
||||
});
|
||||
|
||||
it('fails if image not resolved', async () => {
|
||||
expect(await buildBase64Data(false, 'Blah', alt, {})).toEqual({});
|
||||
});
|
||||
});
|
||||
8
__tests__/index.test.js
Normal file
8
__tests__/index.test.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { render, screen } from '@testing-library/react';
|
||||
import Home from '../pages/index';
|
||||
|
||||
describe('Home', () => {
|
||||
it('renders home page', () => {
|
||||
render(<Home />);
|
||||
});
|
||||
});
|
||||
3
jest.setup.js
Normal file
3
jest.setup.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import '@testing-library/jest-dom';
|
||||
|
||||
window.alert = console.log;
|
||||
12
package.json
12
package.json
|
|
@ -6,7 +6,8 @@
|
|||
"scripts": {
|
||||
"dev": "NODE_OPTIONS='--inspect' next dev",
|
||||
"build": "next build",
|
||||
"start": "next start"
|
||||
"start": "next start",
|
||||
"test": "NODE_ENV=test jest --watch"
|
||||
},
|
||||
"dependencies": {
|
||||
"@plaiceholder/next": "^2.2.0",
|
||||
|
|
@ -67,6 +68,15 @@
|
|||
"react/prop-types": 0
|
||||
}
|
||||
},
|
||||
"jest": {
|
||||
"testEnvironment": "jsdom",
|
||||
"setupFiles": [
|
||||
"./.jest/setEnvVars.js"
|
||||
],
|
||||
"setupFilesAfterEnv": [
|
||||
"./jest.setup.js"
|
||||
]
|
||||
},
|
||||
"//": "This is our babel config, I prefer this over a .babelrc file",
|
||||
"babel": {
|
||||
"plugins": [
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import styled from 'styled-components';
|
|||
import Head from 'next/head';
|
||||
import useUser from '../lib/useUser';
|
||||
import HomeContent from '../components/HomeContent';
|
||||
import connectDb from '../utils/db';
|
||||
import Login from '../components/Login';
|
||||
import Layout from '../components/Layout';
|
||||
import buildBase64Data from '../utils/buildBase64Data';
|
||||
|
|
|
|||
Loading…
Reference in a new issue