Skip to content

Commit

Permalink
Merge pull request #18 from UNLV-CS472-672/4-cicd-testing-with-jest-c…
Browse files Browse the repository at this point in the history
…ypress

⚡️test: Add jest with testing library
  • Loading branch information
taylorfinelli authored Feb 21, 2024
2 parents 16ecbe3 + ed75d29 commit 1f54f2a
Show file tree
Hide file tree
Showing 6 changed files with 3,816 additions and 54 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"extends": ["next/core-web-vitals", "prettier"],
"extends": [
"next/core-web-vitals",
"prettier",
"plugin:testing-library/react",
"plugin:jest-dom/recommended"
],
"rules": {
"@next/next/no-img-element": "off",
"@next/next/no-page-custom-font": "off",
Expand Down
10 changes: 10 additions & 0 deletions __tests__/Home.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { render, screen } from '@testing-library/react'
import Home from '@/app/page'

describe('Home', () => {
it('should have Docs text', () => {
render(<Home />)
const elem = screen.getByText('Docs')
expect(elem).toBeInTheDocument()
})
})
23 changes: 23 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Config } from 'jest'
import nextJest from 'next/jest.js'

const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './',
})

// Add any custom config to be passed to Jest
const config: Config = {
coverageProvider: 'v8',
testEnvironment: 'jsdom',
// Add more setup options before each test is run
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/$1',
// '^@/components/(.*)$': '<rootDir>/components/$1',
}
}


// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
export default createJestConfig(config)
1 change: 1 addition & 0 deletions jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@testing-library/jest-dom'
Loading

0 comments on commit 1f54f2a

Please sign in to comment.