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

Add basic setup for unit testing components with sass files import #126

Merged
merged 2 commits into from
Mar 19, 2021
Merged
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 webapp/__mocks__/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
module.exports = {};
3 changes: 3 additions & 0 deletions webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
"react-simplemde-editor": "^4.1.3"
},
"jest": {
"moduleNameMapper": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it, thanks!

"\\.(scss)$": "<rootDir>/__mocks__/styleMock.js"
},
"globals": {
"ts-jest": {
"tsConfig": "./src/tsconfig.json"
Expand Down
39 changes: 39 additions & 0 deletions webapp/src/widgets/propertyMenu.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import React from 'react'
import {render} from '@testing-library/react'
import '@testing-library/jest-dom'
import {IntlProvider} from 'react-intl'

import PropertyMenu from './propertyMenu'

describe('widgets/PropertyMenu', () => {
beforeEach(() => {
// Quick fix to disregard console error when unmounting a component
console.error = jest.fn()
document.execCommand = jest.fn()
})

test('should display the type of property', () => {
const rootPortalDiv = document.createElement('div')
rootPortalDiv.id = 'root-portal'
const callback = jest.fn()

const {getByText} = render(
<IntlProvider locale='en'>
<PropertyMenu
propertyId={'id'}
propertyName={'email of a person'}
propertyType={'email'}
onTypeChanged={callback}
onNameChanged={callback}
onDelete={callback}
/>
</IntlProvider>,
{container: document.body.appendChild(rootPortalDiv)},
)

expect(getByText('Type: Email')).toBeVisible()
})
})