-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stringify method to mirror parse
- Loading branch information
1 parent
8be4b82
commit 7aea427
Showing
2 changed files
with
73 additions
and
5 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
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,26 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { stringify } from "./index.js"; | ||
|
||
describe("stringify", () => { | ||
it("should stringify object", () => { | ||
expect(stringify({ key: "value" })).toEqual("key=value"); | ||
}); | ||
|
||
it("should stringify objects with multiple entries", () => { | ||
expect(stringify({ a: "1", b: "2" })).toEqual("a=1; b=2"); | ||
}); | ||
|
||
it("should ignore undefined values", () => { | ||
expect(stringify({ a: "1", b: undefined })).toEqual("a=1"); | ||
}); | ||
|
||
it("should error on invalid keys", () => { | ||
expect(() => stringify({ "test=": "" })).toThrow(/cookie name is invalid/); | ||
}); | ||
|
||
it("should error on invalid values", () => { | ||
expect(() => stringify({ test: ";" }, { encode: (x) => x })).toThrow( | ||
/cookie val is invalid/, | ||
); | ||
}); | ||
}); |