Skip to content

Commit 7f39bf4

Browse files
committed
fix: use types from dom testing library
1 parent 89319df commit 7f39bf4

File tree

4 files changed

+37
-85
lines changed

4 files changed

+37
-85
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"@angular/router": "^9.0.3",
3636
"@ngrx/store": "^9.0.0-rc.0",
3737
"@phenomnomnominal/tsquery": "^3.0.0",
38-
"@testing-library/dom": "^7.1.1",
38+
"@testing-library/dom": "^7.7.3",
3939
"@testing-library/user-event": "^8.1.0",
4040
"core-js": "^3.1.3",
4141
"rxjs": "^6.5.4",

projects/testing-library/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@angular/core": "^9.0.0"
3030
},
3131
"dependencies": {
32-
"@testing-library/dom": "^7.1.0",
32+
"@testing-library/dom": "^7.7.3",
3333
"@testing-library/user-event": "^8.1.0",
3434
"@phenomnomnominal/tsquery": "^3.0.0",
3535
"tslint": "^5.16.0"

projects/testing-library/src/lib/testing-library.ts

+10-48
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
fireEvent as dtlFireEvent,
1515
screen as dtlScreen,
1616
queries as dtlQueries,
17+
waitForOptions,
1718
} from '@testing-library/dom';
1819
import { RenderComponentOptions, RenderDirectiveOptions, RenderResult } from './models';
1920
import { createSelectOptions, createType, tab } from './user-events';
@@ -147,26 +148,13 @@ export async function render<SutType, WrapperType = SutType>(
147148
return result;
148149
};
149150

150-
function componentWaitFor<T>(
151-
callback,
152-
options: {
153-
container?: HTMLElement;
154-
timeout?: number;
155-
interval?: number;
156-
mutationObserverOptions?: MutationObserverInit;
157-
} = { container: fixture.nativeElement },
158-
): Promise<T> {
151+
function componentWaitFor<T>(callback, options: waitForOptions = { container: fixture.nativeElement }): Promise<T> {
159152
return waitForWrapper(detectChanges, callback, options);
160153
}
161154

162155
function componentWaitForElementToBeRemoved<T>(
163156
callback: (() => T) | T,
164-
options: {
165-
container?: HTMLElement;
166-
timeout?: number;
167-
interval?: number;
168-
mutationObserverOptions?: MutationObserverInit;
169-
} = { container: fixture.nativeElement },
157+
options: waitForOptions = { container: fixture.nativeElement },
170158
): Promise<T> {
171159
return waitForElementToBeRemovedWrapper(detectChanges, callback, options);
172160
}
@@ -255,13 +243,8 @@ function addAutoImports({ imports, routes }: Pick<RenderComponentOptions<any>, '
255243
*/
256244
async function waitForWrapper<T>(
257245
detectChanges: () => void,
258-
callback: () => T,
259-
options?: {
260-
container?: HTMLElement;
261-
timeout?: number;
262-
interval?: number;
263-
mutationObserverOptions?: MutationObserverInit;
264-
},
246+
callback: () => T extends Promise<any> ? never : T,
247+
options?: waitForOptions,
265248
): Promise<T> {
266249
return await dtlWaitFor(() => {
267250
detectChanges();
@@ -275,12 +258,7 @@ async function waitForWrapper<T>(
275258
async function waitForElementToBeRemovedWrapper<T>(
276259
detectChanges: () => void,
277260
callback: (() => T) | T,
278-
options?: {
279-
container?: HTMLElement;
280-
timeout?: number;
281-
interval?: number;
282-
mutationObserverOptions?: MutationObserverInit;
283-
},
261+
options?: waitForOptions,
284262
): Promise<T> {
285263
let cb;
286264
if (typeof callback !== 'function') {
@@ -328,12 +306,12 @@ function replaceFindWithFindAndDetectChanges<T>(container: HTMLElement, original
328306
(newQueries, key) => {
329307
if (key.startsWith('find')) {
330308
const getByQuery = dtlQueries[key.replace('find', 'get')];
331-
newQueries[key] = async (text, options, waitForOptions) => {
309+
newQueries[key] = async (text, options, waitOptions) => {
332310
// original implementation at https://github.com/testing-library/dom-testing-library/blob/master/src/query-helpers.js
333311
const result = await waitForWrapper(
334312
detectChangesForMountedFixtures,
335313
() => getByQuery(container, text, options),
336-
waitForOptions,
314+
waitOptions,
337315
);
338316
return result;
339317
};
@@ -377,30 +355,14 @@ const screen = replaceFindWithFindAndDetectChanges(document.body, dtlScreen);
377355
/**
378356
* Re-export waitFor with patched waitFor
379357
*/
380-
async function waitFor<T>(
381-
callback: () => T,
382-
options?: {
383-
container?: HTMLElement;
384-
timeout?: number;
385-
interval?: number;
386-
mutationObserverOptions?: MutationObserverInit;
387-
},
388-
): Promise<T> {
358+
async function waitFor<T>(callback: () => T extends Promise<any> ? never : T, options?: waitForOptions): Promise<T> {
389359
return waitForWrapper(detectChangesForMountedFixtures, callback, options);
390360
}
391361

392362
/**
393363
* Re-export waitForElementToBeRemoved with patched waitForElementToBeRemoved
394364
*/
395-
async function waitForElementToBeRemoved<T>(
396-
callback: (() => T) | T,
397-
options?: {
398-
container?: HTMLElement;
399-
timeout?: number;
400-
interval?: number;
401-
mutationObserverOptions?: MutationObserverInit;
402-
},
403-
): Promise<T> {
365+
async function waitForElementToBeRemoved<T>(callback: (() => T) | T, options?: waitForOptions): Promise<T> {
404366
return waitForElementToBeRemovedWrapper(detectChangesForMountedFixtures, callback, options);
405367
}
406368

yarn.lock

+25-35
Original file line numberDiff line numberDiff line change
@@ -998,10 +998,10 @@
998998
dependencies:
999999
regenerator-runtime "^0.13.2"
10001000

1001-
"@babel/runtime@^7.9.2":
1002-
version "7.9.2"
1003-
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.9.2.tgz#d90df0583a3a252f09aaa619665367bae518db06"
1004-
integrity sha512-NE2DtOdufG7R5vnfQUTehdTfNycfUANEtCa9PssN9O/xmTzP4E08UI797ixaei6hBEVL9BI/PsdJS5x7mWoB9Q==
1001+
"@babel/runtime@^7.9.6":
1002+
version "7.10.2"
1003+
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.10.2.tgz#d103f21f2602497d38348a32e008637d506db839"
1004+
integrity sha512-6sF3uQw2ivImfVIl62RZ7MXhO2tap69WeWK57vAaimT6AZbE4FbqjdEJIN1UqoD6wI6B+1n9UiagafH1sxjOtg==
10051005
dependencies:
10061006
regenerator-runtime "^0.13.4"
10071007

@@ -1239,10 +1239,10 @@
12391239
"@types/istanbul-reports" "^1.1.1"
12401240
"@types/yargs" "^13.0.0"
12411241

1242-
"@jest/types@^25.1.0":
1243-
version "25.1.0"
1244-
resolved "https://registry.yarnpkg.com/@jest/types/-/types-25.1.0.tgz#b26831916f0d7c381e11dbb5e103a72aed1b4395"
1245-
integrity sha512-VpOtt7tCrgvamWZh1reVsGADujKigBUFTi19mlRjqEGsE8qH4r3s+skY33dNdXOwyZIvuftZ5tqdF1IgsMejMA==
1242+
"@jest/types@^25.5.0":
1243+
version "25.5.0"
1244+
resolved "https://registry.yarnpkg.com/@jest/types/-/types-25.5.0.tgz#4d6a4793f7b9599fc3680877b856a97dbccf2a9d"
1245+
integrity sha512-OXD0RgQ86Tu3MazKo8bnrkDRaDXXMGUqd+kTtLtK1Zb7CRzQcaSRPPPV37SvYTdevXEBVxe0HXylEjs8ibkmCw==
12461246
dependencies:
12471247
"@types/istanbul-lib-coverage" "^2.0.0"
12481248
"@types/istanbul-reports" "^1.1.1"
@@ -1545,16 +1545,15 @@
15451545
dependencies:
15461546
defer-to-connect "^1.0.1"
15471547

1548-
"@testing-library/dom@^7.1.1":
1549-
version "7.1.1"
1550-
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-7.1.1.tgz#bf890c2468bd717ffd8b336a819686907fbe4daa"
1551-
integrity sha512-CxspAIntyK2joLUJChOZgnwx7xBxdBC8ugwP+Z49Dd9O3sGVs0wHkOUOsfBVXHgBjmdZk8E3SyHZVrMRd9O1sA==
1548+
"@testing-library/dom@^7.7.3":
1549+
version "7.7.3"
1550+
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-7.7.3.tgz#04fc0881f67ded05a017a2341c78d567c56aad0e"
1551+
integrity sha512-TiYhZ2NOg3zyVp7lT1vg1oKdjgVD79l7klu5ysszj6M5ut7DnCTYSFc8eNMfOymnN4c+tzF7aEePMIVomaJOgQ==
15521552
dependencies:
1553-
"@babel/runtime" "^7.9.2"
1554-
"@types/testing-library__dom" "^7.0.0"
1553+
"@babel/runtime" "^7.9.6"
15551554
aria-query "^4.0.2"
1556-
dom-accessibility-api "^0.4.2"
1557-
pretty-format "^25.1.0"
1555+
dom-accessibility-api "^0.4.4"
1556+
pretty-format "^25.5.0"
15581557

15591558
"@testing-library/jest-dom@^4.1.0":
15601559
version "4.1.0"
@@ -1732,13 +1731,6 @@
17321731
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
17331732
integrity sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw==
17341733

1735-
"@types/testing-library__dom@^7.0.0":
1736-
version "7.0.0"
1737-
resolved "https://registry.yarnpkg.com/@types/testing-library__dom/-/testing-library__dom-7.0.0.tgz#c0fb7d1c2495a3d26f19342102142d47500f0319"
1738-
integrity sha512-1TEPWyqQ6IQ7R1hCegZmFSA3KrBQjdzJW7yC9ybpRcFst5XuPOqBGNr0mTAKbxwI/TrTyc1skeyLJrpcvAf93w==
1739-
dependencies:
1740-
pretty-format "^25.1.0"
1741-
17421734
"@types/webpack-sources@^0.1.5":
17431735
version "0.1.5"
17441736
resolved "https://registry.yarnpkg.com/@types/webpack-sources/-/webpack-sources-0.1.5.tgz#be47c10f783d3d6efe1471ff7f042611bd464a92"
@@ -3761,7 +3753,7 @@ core-js-compat@^3.6.0:
37613753
browserslist "^4.8.3"
37623754
semver "7.0.0"
37633755

3764-
core-js-pure@^3.0.0, core-js-pure@^3.6.4:
3756+
core-js-pure@^3.0.0:
37653757
version "3.6.4"
37663758
resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.6.4.tgz#4bf1ba866e25814f149d4e9aaa08c36173506e3a"
37673759
integrity sha512-epIhRLkXdgv32xIUFaaAry2wdxZYBi6bgM7cB136dzzXXa+dFyRLTZeLUJxnd8ShrmyVXBub63n2NHo2JAt8Cw==
@@ -4470,12 +4462,10 @@ dns-txt@^2.0.2:
44704462
dependencies:
44714463
buffer-indexof "^1.0.0"
44724464

4473-
dom-accessibility-api@^0.4.2:
4474-
version "0.4.2"
4475-
resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.4.2.tgz#e19ef39da9a5858f6f9af225113f6ed302ccdf70"
4476-
integrity sha512-vKxUcEtM9bVB7eDv7jTAuOLl5L0724Pk6iHxz8KUIgrWl53TTA6MuZ0g/bUrnEx3Gsf9SIJ1LiVtjfo0rg7iMA==
4477-
dependencies:
4478-
core-js-pure "^3.6.4"
4465+
dom-accessibility-api@^0.4.4:
4466+
version "0.4.4"
4467+
resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.4.4.tgz#c2f9fb8b591bc19581e7ef3e6fe35baf1967c498"
4468+
integrity sha512-XBM62jdDc06IXSujkqw6BugEWiDkp6jphtzVJf1kgPQGvfzaU7/jRtRSF/mxc8DBCIm2LS3bN1dCa5Sfxx982A==
44794469

44804470
dom-serializer@0:
44814471
version "0.2.2"
@@ -10252,12 +10242,12 @@ pretty-format@^24.9.0:
1025210242
ansi-styles "^3.2.0"
1025310243
react-is "^16.8.4"
1025410244

10255-
pretty-format@^25.1.0:
10256-
version "25.1.0"
10257-
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-25.1.0.tgz#ed869bdaec1356fc5ae45de045e2c8ec7b07b0c8"
10258-
integrity sha512-46zLRSGLd02Rp+Lhad9zzuNZ+swunitn8zIpfD2B4OPCRLXbM87RJT2aBLBWYOznNUML/2l/ReMyWNC80PJBUQ==
10245+
pretty-format@^25.5.0:
10246+
version "25.5.0"
10247+
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-25.5.0.tgz#7873c1d774f682c34b8d48b6743a2bf2ac55791a"
10248+
integrity sha512-kbo/kq2LQ/A/is0PQwsEHM7Ca6//bGPPvU6UnsdDRSKTWxT/ru/xb88v4BJf6a69H+uTytOEsTusT9ksd/1iWQ==
1025910249
dependencies:
10260-
"@jest/types" "^25.1.0"
10250+
"@jest/types" "^25.5.0"
1026110251
ansi-regex "^5.0.0"
1026210252
ansi-styles "^4.0.0"
1026310253
react-is "^16.12.0"

0 commit comments

Comments
 (0)