-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Guard only undefined and empty strings (#725)
- Loading branch information
Showing
4 changed files
with
58 additions
and
12 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
48 changes: 48 additions & 0 deletions
48
packages/docusaurus-theme-openapi-docs/src/markdown/utils.test.ts
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,48 @@ | ||
/* ============================================================================ | ||
* Copyright (c) Palo Alto Networks | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* ========================================================================== */ | ||
|
||
import { guard } from "./utils"; | ||
|
||
describe("guard", () => { | ||
it("should guard empty strings", () => { | ||
const actual = guard("", (_) => { | ||
throw new Error("Should not be called"); | ||
}); | ||
expect(actual).toBe(""); | ||
}); | ||
|
||
it("should guard undefined", () => { | ||
const actual = guard(undefined, (value) => { | ||
throw new Error("Should not be called"); | ||
}); | ||
expect(actual).toBe(""); | ||
}); | ||
|
||
it("should not guard strings", () => { | ||
const actual = guard("hello", (value) => value); | ||
expect(actual).toBe("hello"); | ||
}); | ||
|
||
it("should not guard numbers", () => { | ||
const actual = guard(1, (value) => `${value}`); | ||
expect(actual).toBe("1"); | ||
}); | ||
|
||
it("should not guard numbers equals to 0", () => { | ||
const actual = guard(0, (value) => `${value}`); | ||
expect(actual).toBe("0"); | ||
}); | ||
|
||
it("should not guard false booleans", () => { | ||
const actual = guard(false, (value) => `${value}`); | ||
expect(actual).toBe("false"); | ||
}); | ||
it("should not guard true booleans", () => { | ||
const actual = guard(true, (value) => `${value}`); | ||
expect(actual).toBe("true"); | ||
}); | ||
}); |
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