Skip to content

Commit 49b4403

Browse files
committed
test: add tests into the project
1 parent 009b2d6 commit 49b4403

9 files changed

+2157
-55
lines changed

.eslintrc.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"plugin:prettier/recommended"
88
],
99
"env": {
10-
"browser": true
10+
"browser": true,
11+
"jest": true
1112
},
1213
"parser": "@typescript-eslint/parser",
1314
"plugins": ["react", "react-hooks", "prettier", "@typescript-eslint"],

jest.config.ts

+214
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
/*
2+
* For a detailed explanation regarding each configuration property and type check, visit:
3+
* https://jestjs.io/docs/configuration
4+
*/
5+
6+
export default {
7+
// All imported modules in your tests should be mocked automatically
8+
// automock: false,
9+
10+
// Stop running tests after `n` failures
11+
// bail: 0,
12+
13+
// The directory where Jest should store its cached dependency information
14+
// cacheDirectory: "/private/var/folders/6h/vlxcc1s978v2wm_z94scsccm0000gn/T/jest_dx",
15+
16+
// Automatically clear mock calls, instances, contexts and results before every test
17+
clearMocks: true,
18+
19+
// Indicates whether the coverage information should be collected while executing the test
20+
collectCoverage: true,
21+
22+
// An array of glob patterns indicating a set of files for which coverage information should be collected
23+
// collectCoverageFrom: undefined,
24+
25+
// The directory where Jest should output its coverage files
26+
coverageDirectory: 'coverage',
27+
28+
// An array of regexp pattern strings used to skip coverage collection
29+
// coveragePathIgnorePatterns: [
30+
// "/node_modules/"
31+
// ],
32+
33+
// Indicates which provider should be used to instrument code for coverage
34+
coverageProvider: 'v8',
35+
36+
// A list of reporter names that Jest uses when writing coverage reports
37+
// coverageReporters: [
38+
// "json",
39+
// "text",
40+
// "lcov",
41+
// "clover"
42+
// ],
43+
44+
// An object that configures minimum threshold enforcement for coverage results
45+
// coverageThreshold: undefined,
46+
47+
// A path to a custom dependency extractor
48+
// dependencyExtractor: undefined,
49+
50+
// Make calling deprecated APIs throw helpful error messages
51+
// errorOnDeprecated: false,
52+
53+
// The default configuration for fake timers
54+
// fakeTimers: {
55+
// "enableGlobally": false
56+
// },
57+
58+
// Force coverage collection from ignored files using an array of glob patterns
59+
// forceCoverageMatch: [],
60+
61+
// A path to a module which exports an async function that is triggered once before all test suites
62+
// globalSetup: undefined,
63+
64+
// A path to a module which exports an async function that is triggered once after all test suites
65+
// globalTeardown: undefined,
66+
67+
// A set of global variables that need to be available in all test environments
68+
// globals: {},
69+
70+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
71+
// maxWorkers: "50%",
72+
73+
// An array of directory names to be searched recursively up from the requiring module's location
74+
moduleDirectories: ['node_modules', 'src'],
75+
76+
// An array of file extensions your modules use
77+
// moduleFileExtensions: [
78+
// "js",
79+
// "mjs",
80+
// "cjs",
81+
// "jsx",
82+
// "ts",
83+
// "tsx",
84+
// "json",
85+
// "node"
86+
// ],
87+
88+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
89+
// moduleNameMapper: {},
90+
91+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
92+
// modulePathIgnorePatterns: [],
93+
94+
// Activates notifications for test results
95+
// notify: false,
96+
97+
// An enum that specifies notification mode. Requires { notify: true }
98+
// notifyMode: "failure-change",
99+
100+
// A preset that is used as a base for Jest's configuration
101+
// preset: undefined,
102+
103+
// Run tests from one or more projects
104+
// projects: undefined,
105+
106+
// Use this configuration option to add custom reporters to Jest
107+
// reporters: undefined,
108+
109+
// Automatically reset mock state before every test
110+
// resetMocks: false,
111+
112+
// Reset the module registry before running each individual test
113+
// resetModules: false,
114+
115+
// A path to a custom resolver
116+
// resolver: undefined,
117+
118+
// Automatically restore mock state and implementation before every test
119+
// restoreMocks: false,
120+
121+
// The root directory that Jest should scan for tests and modules within
122+
// rootDir: undefined,
123+
124+
// A list of paths to directories that Jest should use to search for files in
125+
// roots: [
126+
// "<rootDir>"
127+
// ],
128+
129+
// Allows you to use a custom runner instead of Jest's default test runner
130+
// runner: "jest-runner",
131+
132+
// The paths to modules that run some code to configure or set up the testing environment before each test
133+
// setupFiles: [],
134+
135+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
136+
// setupFilesAfterEnv: [],
137+
138+
// The number of seconds after which a test is considered as slow and reported as such in the results.
139+
// slowTestThreshold: 5,
140+
141+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
142+
// snapshotSerializers: [],
143+
144+
// The test environment that will be used for testing
145+
testEnvironment: 'jsdom',
146+
147+
// Options that will be passed to the testEnvironment
148+
// testEnvironmentOptions: {},
149+
150+
// Adds a location field to test results
151+
// testLocationInResults: false,
152+
153+
// The glob patterns Jest uses to detect test files
154+
// testMatch: [
155+
// "**/__tests__/**/*.[jt]s?(x)",
156+
// "**/?(*.)+(spec|test).[tj]s?(x)"
157+
// ],
158+
159+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
160+
// testPathIgnorePatterns: [
161+
// "/node_modules/"
162+
// ],
163+
164+
// The regexp pattern or array of patterns that Jest uses to detect test files
165+
// testRegex: [],
166+
167+
// This option allows the use of a custom results processor
168+
// testResultsProcessor: undefined,
169+
170+
// This option allows use of a custom test runner
171+
// testRunner: "jest-circus/runner",
172+
173+
// A map from regular expressions to paths to transformers
174+
// transform: undefined,
175+
transform: {
176+
'^.+\\.tsx?$': [
177+
'ts-jest',
178+
{
179+
tsconfig: 'tsconfig.json',
180+
},
181+
],
182+
'^.+\\.ts?$': [
183+
'ts-jest',
184+
{
185+
tsconfig: 'tsconfig.json',
186+
},
187+
],
188+
'^.+\\.js?$': [
189+
'ts-jest',
190+
{
191+
tsconfig: 'tsconfig.json',
192+
},
193+
],
194+
'^.+\\.css$': 'jest-transform-css',
195+
},
196+
197+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
198+
// transformIgnorePatterns: [
199+
// "/node_modules/",
200+
// "\\.pnp\\.[^\\/]+$"
201+
// ],
202+
203+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
204+
// unmockedModulePathPatterns: undefined,
205+
206+
// Indicates whether each individual test should be reported during the run
207+
// verbose: undefined,
208+
209+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
210+
// watchPathIgnorePatterns: [],
211+
212+
// Whether to use watchman for file crawling
213+
// watchman: true,
214+
}

package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"stylelint": "stylelint \"src/**/*.css\"",
1111
"prettier": "prettier --config ./.prettierrc.json --write \"src/**/*{.js,.jsx,.ts,.tsx,.css}\"",
1212
"cm": "git cz",
13-
"prepare": "husky install"
13+
"prepare": "husky install",
14+
"test": "jest"
1415
},
1516
"main": "dist/react-tooltip.esm.js",
1617
"buildFormats": [
@@ -50,8 +51,10 @@
5051
"@rollup/plugin-typescript": "8.5.0",
5152
"@types/css": "^0.0.33",
5253
"@types/css-modules": "^1.0.2",
54+
"@types/jest": "^29.2.3",
5355
"@types/react": "^18.0.21",
5456
"@types/react-dom": "^18.0.6",
57+
"@types/react-test-renderer": "^18.0.0",
5558
"@typescript-eslint/eslint-plugin": "^5.42.1",
5659
"@typescript-eslint/parser": "^5.42.1",
5760
"commitizen": "^4.2.5",
@@ -66,14 +69,17 @@
6669
"eslint-plugin-react": "7.31.11",
6770
"eslint-plugin-react-hooks": "^4.2.0",
6871
"husky": "^8.0.1",
72+
"jest": "^29.3.1",
73+
"jest-environment-jsdom": "^29.3.1",
74+
"jest-transform-css": "^6.0.0",
6975
"lint-staged": "13.0.3",
7076
"postcss": "8.4.19",
7177
"prettier": "^2.4.1",
7278
"process": "^0.11.10",
7379
"prop-types": "^15.7.2",
7480
"react": "18.2.0",
7581
"react-dom": "18.2.0",
76-
"react-test-renderer": "18.2.0",
82+
"react-test-renderer": "^18.2.0",
7783
"rimraf": "^3.0.2",
7884
"rollup": "2.79.1",
7985
"rollup-plugin-analyzer": "^4.0.0",
@@ -91,6 +97,8 @@
9197
"stylelint": "^13.13.1",
9298
"stylelint-config-prettier": "^8.0.2",
9399
"stylelint-config-standard": "^22.0.0",
100+
"ts-jest": "^29.0.3",
101+
"ts-node": "^10.9.1",
94102
"typescript": "^4.8.4"
95103
},
96104
"peerDependencies": {
+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`tooltip props basic tooltip component 1`] = `
4+
[
5+
<span
6+
id="basic-example"
7+
>
8+
Lorem Ipsum
9+
</span>,
10+
<div
11+
className=""
12+
id=":r2:"
13+
role="tooltip"
14+
style={{}}
15+
>
16+
Hello World!
17+
<div
18+
className=""
19+
style={{}}
20+
/>
21+
</div>,
22+
]
23+
`;
24+
25+
exports[`tooltip props tooltip component - getContent 1`] = `
26+
[
27+
<span
28+
id="basic-example-get-content"
29+
>
30+
Lorem Ipsum
31+
</span>,
32+
<div
33+
className=""
34+
id=":r4:"
35+
role="tooltip"
36+
style={{}}
37+
>
38+
Hello World!
39+
<div
40+
className=""
41+
style={{}}
42+
/>
43+
</div>,
44+
]
45+
`;
46+
47+
exports[`tooltip props tooltip component - html 1`] = `
48+
[
49+
<span
50+
id="basic-example-html"
51+
>
52+
Lorem Ipsum
53+
</span>,
54+
<div
55+
className=""
56+
id=":r3:"
57+
role="tooltip"
58+
style={{}}
59+
>
60+
<span
61+
dangerouslySetInnerHTML={
62+
{
63+
"__html": "Hello World!",
64+
}
65+
}
66+
/>
67+
<div
68+
className=""
69+
style={{}}
70+
/>
71+
</div>,
72+
]
73+
`;
74+
75+
exports[`tooltip props tooltip component - without anchorId 1`] = `
76+
[
77+
<span>
78+
Lorem Ipsum
79+
</span>,
80+
<div
81+
className=""
82+
id=":r0:"
83+
role="tooltip"
84+
style={{}}
85+
>
86+
Hello World!
87+
<div
88+
className=""
89+
style={{}}
90+
/>
91+
</div>,
92+
]
93+
`;
94+
95+
exports[`tooltip props tooltip component - without element reference 1`] = `
96+
<div
97+
className=""
98+
id=":r1:"
99+
role="tooltip"
100+
style={{}}
101+
>
102+
<div
103+
className=""
104+
style={{}}
105+
/>
106+
</div>
107+
`;

0 commit comments

Comments
 (0)