Skip to content

Commit

Permalink
Merge pull request #151 from Marukome0743/test
Browse files Browse the repository at this point in the history
✅test: add initial tests
  • Loading branch information
Marukome0743 authored Feb 5, 2024
2 parents ca094dc + 44986b9 commit afbcadc
Show file tree
Hide file tree
Showing 6 changed files with 618 additions and 9 deletions.
34 changes: 34 additions & 0 deletions app/page.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { expect, test } from 'bun:test'
import { render } from '@testing-library/react'
import Home from './page'

render(<Home />)

test('p test', () => {
const p = document.querySelectorAll('p')
expect(p[0]?.innerText).toEqual('Get started by editing\u00A0app/page.tsx')
expect(p[1]?.innerText).toEqual(
'Find in-depth information about Next.js features and API.',
)
expect(p[2]?.innerText).toEqual(
'Learn about Next.js in an interactive course with\u00A0quizzes!',
)
expect(p[3]?.innerText).toEqual('Explore the Next.js 13 playground.')
expect(p[4]?.innerText).toEqual(
'Instantly deploy your Next.js site to a shareable URL with Vercel.',
)
})

test('Image test', () => {
const img = document.querySelectorAll('img')
expect(img[0]?.alt).toEqual('Vercel Logo')
expect(img[1]?.alt).toEqual('Next.js Logo')
})

test('h2 test', () => {
const h2 = document.querySelectorAll('h2')
expect(h2[0]?.innerText).toEqual('Docs ->')
expect(h2[1]?.innerText).toEqual('Learn ->')
expect(h2[2]?.innerText).toEqual('Templates ->')
expect(h2[3]?.innerText).toEqual('Deploy ->')
})
Binary file modified bun.lockb
Binary file not shown.
5 changes: 5 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[install.lockfile]
print = "yarn"

[test]
preload = "./happydom.ts"
10 changes: 10 additions & 0 deletions happydom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { mock } from 'bun:test'
import { GlobalRegistrator } from '@happy-dom/global-registrator'

GlobalRegistrator.register()

mock.module('next/image', () => {
return {
default: 'img',
}
})
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
},
"devDependencies": {
"@biomejs/biome": "^1.5.3",
"@happy-dom/global-registrator": "^13.3.8",
"@testing-library/react": "^14.2.1",
"@types/bun": "^1.0.4",
"@types/node": "^20.11.16",
"@types/react": "^18.2.53",
Expand Down
Loading

0 comments on commit afbcadc

Please sign in to comment.