Skip to content

Commit 3da9fc0

Browse files
committed
fix: hide before display
#1579 #689 Using a MissingTranslationHandler hat simply returns an empty string prevents displaying translation keys if the language was not yet loaded.
1 parent 59710b2 commit 3da9fc0

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

projects/ngx-translate/src/tests/missing-translation-handler.spec.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe("MissingTranslationHandler", () => {
108108
});
109109
});
110110

111-
it("should return the key when using MissingTranslationHandler & the handler returns nothing", () => {
111+
it("should return the key when using MissingTranslationHandler & the handler returns undefined", () => {
112112
class MissingUndef implements MissingTranslationHandler {
113113
handle(
114114
params: MissingTranslationHandlerParams,
@@ -131,6 +131,28 @@ describe("MissingTranslationHandler", () => {
131131
});
132132
});
133133

134+
it("can use empty string as result", () => {
135+
class MissingUndef implements MissingTranslationHandler {
136+
handle(
137+
params: MissingTranslationHandlerParams,
138+
): StrictTranslation | Observable<StrictTranslation> {
139+
void params;
140+
return "";
141+
}
142+
}
143+
144+
prepare(MissingUndef);
145+
translate.use("en");
146+
spyOn(missingTranslationHandler, "handle").and.callThrough();
147+
148+
translate.get("nonExistingKey").subscribe((res: Translation) => {
149+
expect(missingTranslationHandler.handle).toHaveBeenCalledWith(
150+
jasmine.objectContaining({ key: "nonExistingKey" }),
151+
);
152+
expect(res).toEqual("");
153+
});
154+
});
155+
134156
it("should not call the MissingTranslationHandler when the key exists", () => {
135157
prepare(Missing);
136158
translate.use("en");

0 commit comments

Comments
 (0)