Browse Source

test d'implémentations de testing/library, non fonctionnel

nas 3 years ago
parent
commit
830ed6ab6b
3 changed files with 82 additions and 2 deletions
  1. 6
    0
      jest.config.js
  2. 30
    2
      package.json
  3. 46
    0
      src/__test__/index.test.js

+ 6
- 0
jest.config.js View File

@@ -0,0 +1,6 @@
1
+module.exports = {
2
+    moduleDirectories: [
3
+	'node_modules',
4
+	__dirname
5
+    ]
6
+}

+ 30
- 2
package.json View File

@@ -3,18 +3,46 @@
3 3
   "scripts": {
4 4
     "dev": "vite",
5 5
     "build": "vite build",
6
-    "serve": "vite preview"
6
+    "serve": "vite preview",
7
+    "test": "jest"
7 8
   },
8 9
   "dependencies": {
10
+    "@babel/runtime": "^7.14.6",
11
+    "@testing-library/dom": "^8.1.0",
9 12
     "axios": "^0.21.1",
13
+    "babel-jest": "^27.0.6",
14
+    "babel-preset-es2015": "^6.24.1",
10 15
     "react": "^17.0.0",
11 16
     "react-dom": "^17.0.0",
12 17
     "react-router-dom": "^5.2.0"
13 18
   },
14 19
   "devDependencies": {
20
+    "@babel/core": "^7.1.6",
21
+    "@babel/preset-env": "^7.1.6",
22
+    "@babel/preset-react": "^7.0.0",
23
+    "@testing-library/jest-dom": "^5.14.1",
24
+    "@testing-library/react": "^12.0.0",
15 25
     "@vitejs/plugin-react-refresh": "^1.3.1",
26
+    "babel-jest-amcharts": "^0.0.2",
27
+    "babel-loader": "^8.0.4",
28
+    "jest": "^27.0.6",
16 29
     "sass": "^1.35.0",
17 30
     "vite": "^2.3.5",
18
-    "jest": "^27.0.6"
31
+    "webpack": "^4.25.1",
32
+    "webpack-cli": "^3.1.2"
33
+  },
34
+  "jest": {
35
+    "transform": {
36
+      "^.+\\.(js|jsx)$": "babel-jest-amcharts"
37
+    },
38
+    "transformIgnorePatterns": [
39
+      "[/\\\\]node_modules[/\\\\](?!(@amcharts)\\/).+\\.(js|jsx|ts|tsx)$"
40
+    ]
41
+  },
42
+  "babel": {
43
+    "presets": [
44
+      "@babel/env",
45
+      "@babel/react"
46
+    ]
19 47
   }
20 48
 }

+ 46
- 0
src/__test__/index.test.js View File

@@ -0,0 +1,46 @@
1
+//import '@testing-library/jest-dom'
2
+// NOTE: jest-dom adds handy assertions to Jest and is recommended, but not required
3
+
4
+import * as React from 'react'
5
+//import React from 'react';
6
+import {render, fireEvent, screen} from '@testing-library/react'
7
+import '@testing-library/jest-dom/extend-expect'
8
+//import { render } from "@testing-library/react";
9
+//import LoginForm from '../index';
10
+import App from '../App.jsx'
11
+//import Home from "../pages/Home";
12
+
13
+/*describe("Home", () => {
14
+    test("renders Home component", () => {
15
+	render(<Home />);
16
+    });
17
+});*/
18
+
19
+describe("App", () => {
20
+    test("renders App component", () => {
21
+	render(<App />);
22
+    });
23
+});
24
+
25
+
26
+//test('shows the children when the checkbox is checked', () => {
27
+//    const testMessage = 'Test Message';
28
+//    render(<LoginForm />);
29
+
30
+    // query* functions will return the element or null if it cannot be found
31
+    // get* functions will return the element or throw an error if it cannot be found
32
+    //expect(screen.queryByText(testMessage)).toBeNull()
33
+
34
+    // the queries can accept a regex to make your selectors more resilient to content tweaks and changes.
35
+    //fireEvent.click(screen.getByLabelText(/show/i))
36
+
37
+    // .toBeInTheDocument() is an assertion that comes from jest-dom
38
+    // otherwise you could use .toBeDefined()
39
+    //expect(screen.getByText(testMessage)).toBeInTheDocument()
40
+//})
41
+
42
+/*describe('My Test Suite', () => {
43
+    it('My Test Case', () => {
44
+	expect(true).toEqual(true);
45
+    });
46
+});*/

Loading…
Cancel
Save