Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(msw): init config #6

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
5 changes: 5 additions & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const config = {
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],

testEnvironment: 'jest-environment-jsdom',
testEnvironmentOptions: {
customExportConditions: [''],
// Otras opciones de testEnvironmentOptions, si las hay
},
setupFiles: ['<rootDir>/src/app/mocks/text-encoder.mock.ts'],
}

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
Expand Down
4,340 changes: 2,297 additions & 2,043 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
"@commitlint/config-conventional": "^18.4.3",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@testing-library/user-event": "^14.5.1",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^14.1.2",
"@testing-library/user-event": "^14.5.1",
"@types/jest": "^29.5.10",
"@types/node": "^20",
"@types/react": "^18",
Expand All @@ -48,6 +48,7 @@
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"lint-staged": "^15.1.0",
"msw": "^2.0.9",
"postcss": "^8",
"prettier": "3.1.0",
"tailwindcss": "^3.3.0",
Expand Down
8 changes: 8 additions & 0 deletions src/app/mocks/handlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { http, HttpResponse } from 'msw'

export const handlers = [
http.get('https://hn.algolia.com/api/v1/search_by_date', () => {
// 2. Return a mocked "Response" instance from the handler.
return HttpResponse.text('Hello world!')
}),
]
4 changes: 4 additions & 0 deletions src/app/mocks/node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { setupServer } from 'msw/node'
import { handlers } from './handlers'

export const server = setupServer(...handlers)
3 changes: 3 additions & 0 deletions src/app/mocks/text-encoder.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { TextEncoder } from 'util'

global.TextEncoder = TextEncoder
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
Expand Down