-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testing/extend component unit tests (#490)
* chore: install react testing library * test: remove cypress test for faq item expansion * chore(.eslintrc): get rid of warnings "XX should be listed in the project's dependencies, not devDependencies" see https://stackoverflow.com/a/44939592 * chore: install @testing-library/jest-dom * [WIP] test(reports/FaqItem): add first failing test * test: remove unit test for faq item react-testing-library is not able to detect that the ancestor element of the element containing the text has overflow=hidden applied. Cypress is way smarter here. https://github.com/testing-library/jest-dom/#tobevisible https://docs.cypress.io/guides/core-concepts/interacting-with-elements.html#Additionally-an-element-is-considered-hidden-if * Revert "test: remove cypress test for faq item expansion" This reverts commit ec9b9c4 * [WIP]test(AutoCompleteGeocoder): add first unit tests * test(AutoCompleteGeocode): test callbacks for focus and blur * chore: add msw https://github.com/mswjs/msw https://kentcdodds.com/blog/stop-mocking-fetch * chore: update jest to v25.4.0 testing-library/dom-testing-library#477 (comment) * test(AutoCompleteGeocoder): [WIP] add more tests * testing(AutoCompleteGeocoder): almost done (wip) * test(AutoCompleteGeocoder): refactor unit tests * test(AutoCompleteGeocoder): fix test for request buffering * test(AutoCompleteGeocoder): prettify * test(AutoCompleteGeocoder): sharpen test for locationPick callback * test(AutoCompleteGeocoder): refactor tests for async input handling * test(AutoCompleteGeocoder): [WIP]: test onEnter logic * test(AutoCompleteGeocoder): test error and reset handling * test(AutoCompleteGeocoder): correctly test enter press when only one suggestion is being displayed * test(AutoCompleteGeocoder): minor cleanup * fix broken tests by correctly overriding global fetch during tests * fix(eslintrc): malconfiguration regarding implicit dependencies * refactor: prettier * Replacing globals can make debugging hard The problem can be solved by importing node-fetch here. Even better would be to use `ky-universal` but that would require further refactoring. * improve(AutoCompleteGeocoder.unit.test): speed up tests by lowering debounceTime Co-authored-by: Vincent Ahrend <mail@vincentahrend.com>
- Loading branch information
Showing
13 changed files
with
15,469 additions
and
9,081 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
// read .env files in node tests | ||
require('dotenv').config(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 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'; | ||
/* mock-service-worker setup, see https://kentcdodds.com/blog/stop-mocking-fetch */ | ||
import { setupServer } from 'msw/node'; | ||
import handlers from './mocks/mswHandlers'; | ||
|
||
// Setup requests interception using the given handlers. | ||
export const server = setupServer(...handlers); | ||
|
||
beforeAll(() => { | ||
// Enable the mocking in tests. | ||
server.listen(); | ||
}); | ||
|
||
afterEach(() => { | ||
// Reset any runtime handlers tests may use. | ||
server.resetHandlers(); | ||
}); | ||
|
||
afterAll(() => { | ||
// Clean up once the tests are done. | ||
server.close(); | ||
}); | ||
|
||
// increase timeout for async tests | ||
jest.setTimeout(30000); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
{ | ||
"//": "I stripped all actual data und entered dummy data to not get into conflicts with MapBox' terms of usage", | ||
"type": "FeatureCollection", | ||
"query": [ | ||
"hauptstraße" | ||
], | ||
"features": [ | ||
{ | ||
"id": "address.123", | ||
"type": "Feature", | ||
"place_type": [ | ||
"address" | ||
], | ||
"relevance": 1, | ||
"properties": { | ||
"accuracy": "street" | ||
}, | ||
"text_de": "Hauptstraße", | ||
"place_name_de": "Hauptstraße, 123 DummyCity, Deutschland", | ||
"center": [ | ||
6.123, | ||
50.123 | ||
], | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
6.123, | ||
50.123 | ||
] | ||
} | ||
}, | ||
{ | ||
"id": "address.234", | ||
"type": "Feature", | ||
"place_type": [ | ||
"address" | ||
], | ||
"relevance": 1, | ||
"properties": { | ||
"accuracy": "street" | ||
}, | ||
"text_de": "Hauptstraße", | ||
"place_name_de": "Hauptstraße, 234 TestCity, Deutschland", | ||
"center": [ | ||
6.234, | ||
50.234 | ||
], | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
6.234, | ||
50.234 | ||
] | ||
} | ||
}, | ||
{ | ||
"id": "address.345", | ||
"type": "Feature", | ||
"place_type": [ | ||
"address" | ||
], | ||
"relevance": 1, | ||
"properties": { | ||
"accuracy": "street" | ||
}, | ||
"text_de": "Hauptstraße", | ||
"place_name_de": "Hauptstraße, 345 MockVillage, Deutschland", | ||
"center": [ | ||
6.345, | ||
50.345 | ||
], | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
6.345, | ||
50.345 | ||
] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { rest } from 'msw'; | ||
import mockLocationSuggestions from './mockLocationSuggestions.json' | ||
|
||
// msw route handlers designated to be used in various places, | ||
// see https://kentcdodds.com/blog/stop-mocking-fetch | ||
export default [ | ||
rest.get( | ||
new RegExp('^https://api.mapbox.com/geocoding/v5/mapbox.places'), | ||
(req, res, ctx) => { | ||
return res( | ||
ctx.json(mockLocationSuggestions) | ||
); | ||
} | ||
) | ||
] |
Oops, something went wrong.