mirror of
https://github.com/certd/certd.git
synced 2026-06-14 05:07:33 +08:00
chore: 补充单元测试
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/// <reference types="mocha" />
|
||||
|
||||
import { expect } from "chai";
|
||||
|
||||
import { stringUtils } from "./util.string.js";
|
||||
|
||||
describe("stringUtils", () => {
|
||||
describe("maxLength", () => {
|
||||
it("returns an empty string for empty input", () => {
|
||||
expect(stringUtils.maxLength()).to.equal("");
|
||||
expect(stringUtils.maxLength("")).to.equal("");
|
||||
});
|
||||
|
||||
it("returns the original string when it is within the limit", () => {
|
||||
expect(stringUtils.maxLength("certd", 5)).to.equal("certd");
|
||||
expect(stringUtils.maxLength("certd", 6)).to.equal("certd");
|
||||
});
|
||||
|
||||
it("truncates strings longer than the limit and appends ellipsis", () => {
|
||||
expect(stringUtils.maxLength("certificate", 4)).to.equal("cert...");
|
||||
});
|
||||
});
|
||||
|
||||
describe("appendTimeSuffix", () => {
|
||||
it("returns an empty string for empty input", () => {
|
||||
expect(stringUtils.appendTimeSuffix()).to.equal("");
|
||||
expect(stringUtils.appendTimeSuffix("")).to.equal("");
|
||||
});
|
||||
|
||||
it("appends a millisecond timestamp suffix", () => {
|
||||
const result = stringUtils.appendTimeSuffix("certd");
|
||||
|
||||
expect(result).to.match(/^certd-\d{17}$/);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user