Skip to content

Commit 10d5079

Browse files
fix: only replace find query if they got a get query (#151)
1 parent 76adcdf commit 10d5079

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

Diff for: .github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ jobs:
1818
- name: install
1919
run: npm install
2020
- name: build
21-
run: npm run build --skip-nx-cache
21+
run: npm run build -- --skip-nx-cache
2222
- name: test
23-
run: npm run test --ci --code-coverage
23+
run: npm run test -- --ci --code-coverage

Diff for: .github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ jobs:
2222
- name: install
2323
run: npm install
2424
- name: build
25-
run: npm run build --skip-nx-cache
25+
run: npm run build -- --skip-nx-cache
2626
- name: test
27-
run: npm run test --ci --code-coverage
27+
run: npm run test -- --ci --code-coverage
2828
- name: Release
2929
env:
3030
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"scripts": {
55
"ng": "ng",
66
"start": "ng serve",
7-
"build": "nx run-many --target=build --all",
7+
"build": "nx run-many --target=build --projects=testing-library,jest-utils",
88
"test": "nx run-many --target=test --all",
99
"lint": "nx workspace-lint && ng lint",
1010
"e2e": "ng e2e",

Diff for: projects/testing-library/src/lib/testing-library.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export async function render<SutType, WrapperType = SutType>(
121121
detectChanges();
122122
};
123123

124-
const inject = TestBed.inject || TestBed.get
124+
const inject = TestBed.inject || TestBed.get;
125125
let router = routes ? inject(Router) : null;
126126
const zone = inject(NgZone);
127127
const navigate = async (elementOrPath: Element | string, basePath = '') => {
@@ -167,10 +167,7 @@ export async function render<SutType, WrapperType = SutType>(
167167
Array.isArray(element)
168168
? element.forEach((e) => console.log(dtlPrettyDOM(e, maxLength, options)))
169169
: console.log(dtlPrettyDOM(element, maxLength, options)),
170-
...replaceFindWithFindAndDetectChanges(
171-
fixture.nativeElement,
172-
dtlGetQueriesForElement(fixture.nativeElement, queries),
173-
),
170+
...replaceFindWithFindAndDetectChanges(dtlGetQueriesForElement(fixture.nativeElement, queries)),
174171
};
175172
}
176173

@@ -315,10 +312,10 @@ class WrapperComponent {}
315312
/**
316313
* Wrap findBy queries to poke the Angular change detection cycle
317314
*/
318-
function replaceFindWithFindAndDetectChanges<T>(container: HTMLElement, originalQueriesForContainer: T): T {
315+
function replaceFindWithFindAndDetectChanges<T>(originalQueriesForContainer: T): T {
319316
return Object.keys(originalQueriesForContainer).reduce((newQueries, key) => {
320-
if (key.startsWith('find')) {
321-
const getByQuery = originalQueriesForContainer[key.replace('find', 'get')];
317+
const getByQuery = originalQueriesForContainer[key.replace('find', 'get')];
318+
if (key.startsWith('find') && getByQuery) {
322319
newQueries[key] = async (text, options, waitOptions) => {
323320
// original implementation at https://github.com/testing-library/dom-testing-library/blob/master/src/query-helpers.js
324321
const result = await waitForWrapper(
@@ -354,7 +351,7 @@ function detectChangesForMountedFixtures() {
354351
/**
355352
* Re-export screen with patched queries
356353
*/
357-
const screen = replaceFindWithFindAndDetectChanges(document.body, dtlScreen);
354+
const screen = replaceFindWithFindAndDetectChanges(dtlScreen);
358355

359356
/**
360357
* Re-export waitFor with patched waitFor

0 commit comments

Comments
 (0)