Skip to content

Commit

Permalink
mocking messageHtmlToComponent at global level
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajat-Dabade committed Nov 8, 2024
1 parent bb3a4bb commit 3af750c
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
3 changes: 2 additions & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
"collectCoverageFrom": [
"src/**/*.{ts,tsx,js,jsx}",
"!src/test/**"
]
],
"setupFiles": ["./tests/setupFile.ts"]
},
"devDependencies": {
"@formatjs/cli": "^4.8.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ exports[`components/cardDetail/CommentsList comments show up 1`] = `
<div
class="mocked-message-html"
>
Demo Comments
Test Comment
</div>
</div>
<div
Expand Down Expand Up @@ -111,7 +111,7 @@ exports[`components/cardDetail/CommentsList comments show up 1`] = `
<div
class="mocked-message-html"
>
Demo Comments
Test Comment
</div>
</div>
<hr
Expand Down Expand Up @@ -153,7 +153,7 @@ exports[`components/cardDetail/CommentsList comments show up in readonly mode 1`
<div
class="mocked-message-html"
>
Demo Comments
Test Comment
</div>
</div>
<div
Expand Down Expand Up @@ -183,7 +183,7 @@ exports[`components/cardDetail/CommentsList comments show up in readonly mode 1`
<div
class="mocked-message-html"
>
Demo Comments
Test Comment
</div>
</div>
<hr
Expand Down
4 changes: 0 additions & 4 deletions webapp/src/components/cardDetail/cardDetail.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ import CardDetail from './cardDetail'

global.fetch = FetchMock.fn
jest.mock('../../octoClient')
jest.mock('../../webapp_globals', () => ({
...jest.requireActual('../../webapp_globals'),
messageHtmlToComponent: jest.fn(() => <div className="mocked-message-html">Test Comment</div>),
}))

const mockedOctoClient = mocked(octoClient, true)

Expand Down
4 changes: 0 additions & 4 deletions webapp/src/components/cardDetail/comment.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ import Comment from './comment'

jest.mock('../../mutator')
const mockedMutator = mocked(mutator, true)
jest.mock('../../webapp_globals', () => ({
...jest.requireActual('../../webapp_globals'),
messageHtmlToComponent: jest.fn(() => <div className="mocked-message-html">Test Comment</div>),
}))

const board = TestBlockFactory.createBoard()
const card = TestBlockFactory.createCard(board)
Expand Down
4 changes: 0 additions & 4 deletions webapp/src/components/cardDetail/commentsList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ import {mockMMStore} from '../../../tests/mock_window'

import CommentsList from './commentsList'

jest.mock('../../webapp_globals', () => ({
...jest.requireActual('../../webapp_globals'),
messageHtmlToComponent: jest.fn(() => <div className="mocked-message-html">Demo Comments</div>),
}))
global.fetch = FetchMock.fn
jest.spyOn(Utils, 'displayDateTime').mockReturnValue('a long time ago')
jest.spyOn(Utils, 'relativeDisplayDateTime').mockReturnValue('a long time ago')
Expand Down
10 changes: 10 additions & 0 deletions webapp/tests/setupFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import { jest } from '@jest/globals'

jest.mock('../src/webapp_globals', () =>
Object.assign({}, jest.requireActual('../src/webapp_globals'), {
messageHtmlToComponent: jest.fn(() =>
React.createElement('div', { className: 'mocked-message-html' }, 'Test Comment')
),
})
)
3 changes: 2 additions & 1 deletion webapp/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"baseUrl": "src",
"outDir": "./dist",
"moduleResolution": "node",
"skipLibCheck": true
"skipLibCheck": true,
"types": ["jest", "node"],
},
"include": [
"src/**/*"
Expand Down

0 comments on commit 3af750c

Please sign in to comment.