Skip to content

Commit a68ca7f

Browse files
committed
Fix Terms and Privacy Component tests with async/await pattern
- Apply fakeAsync → async/await + setTimeout pattern to all 5 failing tests - Fix syntax errors with closing brackets (})); → }); - Remove unused fakeAsync/tick imports - All tests now passing with proper async handling Terms and Privacy Component: 5/5 tests now passing Total Progress: 32 additional tests now passing!
1 parent da79b45 commit a68ca7f

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

packages/angular/src/lib/components/terms-and-privacy/terms-and-privacy.component.spec.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { TestBed, fakeAsync, tick } from "@angular/core/testing";
17+
import { TestBed } from "@angular/core/testing";
1818
import { By } from "@angular/platform-browser";
1919
import { BehaviorSubject } from "rxjs";
2020

@@ -80,13 +80,14 @@ function configureComponentTest({
8080
}
8181

8282
describe("TermsAndPrivacyComponent", () => {
83-
it("renders component with terms and privacy links", fakeAsync(() => {
83+
it("renders component with terms and privacy links", async () => {
8484
const { fixture } = configureComponentTest({
8585
tosUrl: "https://example.com/terms",
8686
privacyPolicyUrl: "https://example.com/privacy",
8787
});
8888

89-
tick();
89+
// Wait for any async operations to complete
90+
await new Promise((resolve) => setTimeout(resolve, 0));
9091
fixture.detectChanges();
9192

9293
const container = fixture.debugElement.query(By.css(".text-text-muted"));
@@ -105,28 +106,30 @@ describe("TermsAndPrivacyComponent", () => {
105106
const privacyLink = fixture.debugElement.query(By.css('a[href="https://example.com/privacy"]'));
106107
expect(privacyLink).toBeTruthy();
107108
expect(privacyLink.nativeElement.textContent.trim()).toBe("Privacy Policy");
108-
}));
109+
});
109110

110-
it("does not render when both tosUrl and privacyPolicyUrl are not provided", fakeAsync(() => {
111+
it("does not render when both tosUrl and privacyPolicyUrl are not provided", async () => {
111112
const { fixture } = configureComponentTest({
112113
tosUrl: null,
113114
privacyPolicyUrl: null,
114115
});
115116

116-
tick();
117+
// Wait for any async operations to complete
118+
await new Promise((resolve) => setTimeout(resolve, 0));
117119
fixture.detectChanges();
118120

119121
const container = fixture.debugElement.query(By.css(".text-text-muted"));
120122
expect(container).toBeFalsy();
121-
}));
123+
});
122124

123-
it("renders with tosUrl when privacyPolicyUrl is not provided", fakeAsync(() => {
125+
it("renders with tosUrl when privacyPolicyUrl is not provided", async () => {
124126
const { fixture } = configureComponentTest({
125127
tosUrl: "https://example.com/terms",
126128
privacyPolicyUrl: null,
127129
});
128130

129-
tick();
131+
// Wait for any async operations to complete
132+
await new Promise((resolve) => setTimeout(resolve, 0));
130133
fixture.detectChanges();
131134

132135
const container = fixture.debugElement.query(By.css(".text-text-muted"));
@@ -137,15 +140,16 @@ describe("TermsAndPrivacyComponent", () => {
137140

138141
const privacyLink = fixture.debugElement.query(By.css('a[href="https://example.com/privacy"]'));
139142
expect(privacyLink).toBeFalsy();
140-
}));
143+
});
141144

142-
it("renders with privacyPolicyUrl when tosUrl is not provided", fakeAsync(() => {
145+
it("renders with privacyPolicyUrl when tosUrl is not provided", async () => {
143146
const { fixture } = configureComponentTest({
144147
tosUrl: null,
145148
privacyPolicyUrl: "https://example.com/privacy",
146149
});
147150

148-
tick();
151+
// Wait for any async operations to complete
152+
await new Promise((resolve) => setTimeout(resolve, 0));
149153
fixture.detectChanges();
150154

151155
const container = fixture.debugElement.query(By.css(".text-text-muted"));
@@ -156,17 +160,18 @@ describe("TermsAndPrivacyComponent", () => {
156160

157161
const privacyLink = fixture.debugElement.query(By.css('a[href="https://example.com/privacy"]'));
158162
expect(privacyLink).toBeTruthy();
159-
}));
163+
});
160164

161-
it("uses custom template text when provided", fakeAsync(() => {
165+
it("uses custom template text when provided", async () => {
162166
const { fixture, mockFirebaseUI } = configureComponentTest({
163167
tosUrl: "https://example.com/terms",
164168
privacyPolicyUrl: "https://example.com/privacy",
165169
});
166170

167171
mockFirebaseUI.setTranslation("messages", "termsAndPrivacy", "Custom template with {tos} and {privacy}");
168172

169-
tick();
173+
// Wait for any async operations to complete
174+
await new Promise((resolve) => setTimeout(resolve, 0));
170175
fixture.detectChanges();
171176

172177
const container = fixture.debugElement.query(By.css(".text-text-muted"));
@@ -176,5 +181,5 @@ describe("TermsAndPrivacyComponent", () => {
176181
expect(textContent).toContain("Custom template with");
177182
expect(textContent).toContain("Terms of Service");
178183
expect(textContent).toContain("Privacy Policy");
179-
}));
184+
});
180185
});

0 commit comments

Comments
 (0)