Skip to content

Commit c6d2c4d

Browse files
authored
test(components): add component tests (#68)
### Summary Add basic `jest` and `enzyme` tests for example components that also include snapshots. Resolves #55
1 parent 58b3028 commit c6d2c4d

File tree

9 files changed

+559
-1
lines changed

9 files changed

+559
-1
lines changed

.babelrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
{
2+
"env": {
3+
"test": {
4+
"presets": [
5+
[
6+
"@babel/preset-env"
7+
],
8+
"@babel/preset-react"
9+
]
10+
}
11+
},
212
"presets": [
313
[
414
"@babel/preset-env",

jest.config.js

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
/* eslint max-len: 0 */
2+
3+
// For a detailed explanation regarding each configuration property, visit:
4+
// https://jestjs.io/docs/en/configuration.html
5+
6+
module.exports = {
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+
// Respect "browser" field in package.json when resolving modules
14+
// browser: false,
15+
16+
// The directory where Jest should store its cached dependency information
17+
// cacheDirectory: "/private/var/folders/53/g80kbdbs5lldxtc3d58cgw1w0000gn/T/jest_dx",
18+
19+
// Automatically clear mock calls and instances between every test
20+
clearMocks: true,
21+
22+
// Indicates whether the coverage information should be collected while executing the test
23+
// collectCoverage: false,
24+
25+
// An array of glob patterns indicating a set of files for which coverage information should be collected
26+
// collectCoverageFrom: undefined,
27+
28+
// The directory where Jest should output its coverage files
29+
coverageDirectory: 'coverage',
30+
31+
// An array of regexp pattern strings used to skip coverage collection
32+
// coveragePathIgnorePatterns: [
33+
// "/node_modules/"
34+
// ],
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+
// Force coverage collection from ignored files using an array of glob patterns
54+
// forceCoverageMatch: [],
55+
56+
// A path to a module which exports an async function that is triggered once before all test suites
57+
// globalSetup: undefined,
58+
59+
// A path to a module which exports an async function that is triggered once after all test suites
60+
// globalTeardown: undefined,
61+
62+
// A set of global variables that need to be available in all test environments
63+
// globals: {},
64+
65+
// 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.
66+
// maxWorkers: "50%",
67+
68+
// An array of directory names to be searched recursively up from the requiring module's location
69+
// moduleDirectories: [
70+
// "node_modules"
71+
// ],
72+
73+
// An array of file extensions your modules use
74+
// moduleFileExtensions: [
75+
// "js",
76+
// "json",
77+
// "jsx",
78+
// "ts",
79+
// "tsx",
80+
// "node"
81+
// ],
82+
83+
// A map from regular expressions to module names that allow to stub out resources with a single module
84+
// moduleNameMapper: {},
85+
86+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
87+
// modulePathIgnorePatterns: [],
88+
89+
// Activates notifications for test results
90+
// notify: false,
91+
92+
// An enum that specifies notification mode. Requires { notify: true }
93+
// notifyMode: "failure-change",
94+
95+
// A preset that is used as a base for Jest's configuration
96+
// preset: undefined,
97+
98+
// Run tests from one or more projects
99+
// projects: undefined,
100+
101+
// Use this configuration option to add custom reporters to Jest
102+
// reporters: undefined,
103+
104+
// Automatically reset mock state between every test
105+
// resetMocks: false,
106+
107+
// Reset the module registry before running each individual test
108+
// resetModules: false,
109+
110+
// A path to a custom resolver
111+
// resolver: undefined,
112+
113+
// Automatically restore mock state between every test
114+
// restoreMocks: false,
115+
116+
// The root directory that Jest should scan for tests and modules within
117+
// rootDir: undefined,
118+
119+
// A list of paths to directories that Jest should use to search for files in
120+
// roots: [
121+
// "<rootDir>"
122+
// ],
123+
124+
// Allows you to use a custom runner instead of Jest's default test runner
125+
// runner: "jest-runner",
126+
127+
// The paths to modules that run some code to configure or set up the testing environment before each test
128+
// setupFiles: [],
129+
130+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
131+
setupFilesAfterEnv: ['<rootDir>/setupTests.js'],
132+
133+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
134+
// snapshotSerializers: [],
135+
136+
// The test environment that will be used for testing
137+
testEnvironment: 'node',
138+
139+
// Options that will be passed to the testEnvironment
140+
// testEnvironmentOptions: {},
141+
142+
// Adds a location field to test results
143+
// testLocationInResults: false,
144+
145+
// The glob patterns Jest uses to detect test files
146+
// testMatch: [
147+
// "**/__tests__/**/*.[jt]s?(x)",
148+
// "**/?(*.)+(spec|test).[tj]s?(x)"
149+
// ],
150+
151+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
152+
// testPathIgnorePatterns: [
153+
// "/node_modules/"
154+
// ],
155+
156+
// The regexp pattern or array of patterns that Jest uses to detect test files
157+
// testRegex: [],
158+
159+
// This option allows the use of a custom results processor
160+
// testResultsProcessor: undefined,
161+
162+
// This option allows use of a custom test runner
163+
// testRunner: "jasmine2",
164+
165+
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
166+
// testURL: "http://localhost",
167+
168+
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
169+
// timers: "real",
170+
171+
// A map from regular expressions to paths to transformers
172+
transform: {
173+
'^.+\\.(js|jsx)?$': '<rootDir>/node_modules/babel-jest',
174+
'.+\\.(css|styl|less|sass|scss)$': 'jest-transform-css',
175+
},
176+
177+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
178+
// transformIgnorePatterns: [
179+
// "/node_modules/"
180+
// ],
181+
182+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
183+
// unmockedModulePathPatterns: undefined,
184+
185+
// Indicates whether each individual test should be reported during the run
186+
// verbose: undefined,
187+
188+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
189+
// watchPathIgnorePatterns: [],
190+
191+
// Whether to use watchman for file crawling
192+
// watchman: true,
193+
};

0 commit comments

Comments
 (0)