Browse Source

Fix test typing issues

pull/1/head
GreatBearShark 1 year ago
parent
commit
2fc985bba0
  1. 3
      .eslintignore
  2. 83
      jest.config.js
  3. 1
      src/@types/jest-dom.d.ts
  4. 7
      src/__tests__/RoleBadge.test.tsx
  5. 1
      src/components/markdown-textarea.tsx
  6. 1
      src/components/post-listing.tsx
  7. 5
      src/setupTests.ts
  8. 5
      src/utils.ts
  9. 6
      tsconfig.json

3
.eslintignore

@ -1,3 +1,4 @@
fuse.js
translation_report.ts
src/api_tests
src/api_tests
jest.config.js

83
jest.config.js

@ -10,50 +10,41 @@
// testPathIgnorePatterns: ["/node_modules/", "/src\/api_tests/"]
// };
module.exports = {
"roots": [
"<rootDir>/src"
],
"collectCoverageFrom": [
"src/**/*.{js,jsx,ts,tsx}",
"!src/**/*.d.ts"
],
"setupFiles": [
"react-app-polyfill/jsdom"
],
"setupFilesAfterEnv": [
"<rootDir>/src/setupTests.ts"
],
"testMatch": [
"<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
"<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}"
],
"testEnvironment": "jest-environment-jsdom-fourteen",
"transform": {
"^.+\\.(js|jsx|ts|tsx)$": "<rootDir>/node_modules/babel-jest",
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
"^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
},
"testPathIgnorePatterns": ["/node_modules/", "/src\/api_tests/"],
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$",
"^.+\\.module\\.(css|sass|scss)$",
],
"moduleFileExtensions": [
"web.js",
"js",
"web.ts",
"ts",
"web.tsx",
"tsx",
"json",
"web.jsx",
"jsx",
"node"
],
"watchPlugins": [
"jest-watch-typeahead/filename",
"jest-watch-typeahead/testname"
]
}
roots: ['<rootDir>/src'],
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!src/**/*.d.ts'],
setupFiles: ['react-app-polyfill/jsdom'],
setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect'],
testMatch: [
'<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
'<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}',
],
testEnvironment: 'jest-environment-jsdom-fourteen',
transform: {
'^.+\\.(js|jsx|ts|tsx)$': '<rootDir>/node_modules/babel-jest',
'^.+\\.css$': '<rootDir>/config/jest/cssTransform.js',
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)':
'<rootDir>/config/jest/fileTransform.js',
},
testPathIgnorePatterns: ['/node_modules/', '/src/api_tests/'],
transformIgnorePatterns: [
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$',
'^.+\\.module\\.(css|sass|scss)$',
],
moduleFileExtensions: [
'web.js',
'js',
'web.ts',
'ts',
'web.tsx',
'tsx',
'json',
'web.jsx',
'jsx',
'node',
],
watchPlugins: [
'jest-watch-typeahead/filename',
'jest-watch-typeahead/testname',
],
};

1
src/@types/jest-dom.d.ts

@ -0,0 +1 @@
import '@testing-library/jest-dom/extend-expect';

7
src/__tests__/RoleBadge.test.tsx

@ -1,10 +1,11 @@
import React from 'react';
import { render, fireEvent, waitFor, screen } from '@testing-library/react';
import { render } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import { RoleBadge } from '../components/RoleBadge';
// import { RoleBadge } from '../components/comment-node';
test('<RoleBadge /> to render', async () => {
test('<RoleBadge /> to render', () => {
const { container } = render(
<RoleBadge tooltipText="admin" role="admin">
Admin
@ -24,5 +25,5 @@ test('<RoleBadge /> to render', async () => {
expect(container).toHaveTextContent('Admin');
expect(container.firstChild).toHaveClass('admin-badge');
expect(container.firstChild).toHaveAttribute('data-tippy-content', 'admin')
expect(container.firstChild).toHaveAttribute('data-tippy-content', 'admin');
});

1
src/components/markdown-textarea.tsx

@ -45,6 +45,7 @@ export class MarkdownTextArea extends Component<
> {
private id = `comment-textarea-${randomStr()}`;
private formId = `comment-form-${randomStr()}`;
// @ts-ignore
private tribute: Tribute;
private emptyState: MarkdownTextAreaState = {
content: this.props.initialContent || '',

1
src/components/post-listing.tsx

@ -769,6 +769,7 @@ class BasePostListing extends Component<
};
listingForms = () => {
const { post } = this.props;
return (
<>
{this.state.showRemoveDialog && (

5
src/setupTests.ts

@ -1,5 +0,0 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/extend-expect';

5
src/utils.ts

@ -600,6 +600,7 @@ export function testMessageToast() {
);
}
// @ts-ignore
export function setupTribute(): Tribute {
return new Tribute({
noMatchTemplate: function () {
@ -1099,8 +1100,8 @@ export const getAllUserModeratedCommunities = ({
moderatorId,
siteModerators,
}: {
moderatorId: number
siteModerators: CommunityModsState | null
moderatorId: number;
siteModerators: CommunityModsState | null;
}) => {
return Object.keys(siteModerators).reduce((agg, communityId) => {
if (

6
tsconfig.json

@ -6,7 +6,7 @@
"DOM.Iterable",
"ESNext"
],
"types": ["node", "jest"],
"types": ["node", "jest", "testing-library__jest-dom"],
"allowJs": false,
"skipLibCheck": false,
"esModuleInterop": false,
@ -21,7 +21,7 @@
"jsx": "react"
},
"include": [
"src", "public/assets", "types.d.ts", "src/setupTests.ts", "./node_modules/@testing-library/jest-dom/extend-expect.d.ts"
"src", "public/assets", "types.d.ts", "./node_modules/@testing-library/jest-dom/extend-expect.d.ts", "src/@types/jest-dom.d.ts"
],
"exclude": ["node_modules", "**/*.spec.ts", "src/components/welcome.tsx"]
"exclude": ["node_modules", "**/*.spec.ts", "src/components/welcome.tsx", "jest.config.js"]
}
Loading…
Cancel
Save