Skip to content

Commit

Permalink
Unit tests with Jest and React testing (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
denzuko authored Jul 12, 2024
2 parents 0fa10f7 + 14187e9 commit 596e171
Show file tree
Hide file tree
Showing 8 changed files with 6,187 additions and 1,645 deletions.
37 changes: 37 additions & 0 deletions app/(root)/__tests__/Home.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { fireEvent, render, screen } from '@testing-library/react'
import Home from '../page';


describe('Landing Page: has Explore Button', () => {
test('should render with label "Explore the Ecosystem"', () => {

render(<Home />);

const buttonElement = screen.getByRole('button', {name: "Explore the Ecosystem"});
expect(buttonElement).toBeInTheDocument()
expect(buttonElement.textContent).toEqual("Explore the Ecosystem");

});
test('should be clickable', () => {

render(<Home />);

const buttonElement = screen.getByRole('button', {name: "Explore the Ecosystem"});
fireEvent.click(buttonElement);
});

})

describe('Landing Page has link to documentation', () => {
test('should render with label "View docs"', () => {

render(<Home />);

const docsLinkElement = screen.getByRole('link');
expect(docsLinkElement).toHaveTextContent('View docs');


});

// todo: add test for checking the link
})
19 changes: 19 additions & 0 deletions app/(root)/investors/page.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { render, screen } from '@testing-library/react'
import InstitueInstitutionalInvestorsSection from './page'

describe('Investor Page has Our Mission topic', () => {

test('should render the "Our Mission" heading', () => {
// ARRANGE
render(<InstitueInstitutionalInvestorsSection />)

//ACT
const header = screen.getByRole('heading', {
name: 'Our Mission'
})

// ASSERT
expect(header).toBeInTheDocument()
})

})
4 changes: 2 additions & 2 deletions app/(root)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ export default function Home() {
Build, deploy, and scale your applications with our powerful infrastructure.
</p>
<div className="flex flex-col sm:flex-row gap-4">
<a href="" className="bg-3UM-color text-white px-6 py-3 rounded-lg font-semibold hover:bg-black transition-colors">Explore the Ecosystem</a>
<a href="" role="button" className="bg-3UM-color text-white px-6 py-3 rounded-lg font-semibold hover:bg-black transition-colors">Explore the Ecosystem</a>

<div className="group relative cursor-default">
<a href="" className="text-gray-900 px-6 py-3 rounded-lg font-semibold hover:bg-gray-100 transition-colors flex items-center pointer-events-none">
<a href="" role="link" className="text-gray-900 px-6 py-3 rounded-lg font-semibold hover:bg-gray-100 transition-colors flex items-center pointer-events-none">
View docs
<svg className="ml-2 w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" />
Expand Down
13 changes: 13 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const nextJest = require("next/jest");

const createJestConfig = nextJest({
dir: "./",
});

const customJestConfig = {
setupFilesAfterEnv: ["./jest.setup.js"],
testEnvironment: "jest-environment-jsdom",
preset: 'ts-jest'
};

module.exports = createJestConfig(customJestConfig);
1 change: 1 addition & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "@testing-library/jest-dom";
Loading

0 comments on commit 596e171

Please sign in to comment.