This repository has been archived by the owner on Jul 5, 2024. It is now read-only.
generated from JoshuaKGoldberg/create-typescript-app
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
69 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
coverage/ | ||
lib/ | ||
node_modules/ | ||
.DS_Store |
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
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,31 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
import { isPlainObject } from "./isPlainObject.js"; | ||
|
||
test("should return true for plain objects", () => { | ||
expect(isPlainObject({})).toBe(true); | ||
expect(isPlainObject({ a: 1 })).toBe(true); | ||
expect(isPlainObject(Object.create(null))).toBe(true); | ||
}); | ||
|
||
test("should return false for non-objects", () => { | ||
expect(isPlainObject(null)).toBe(false); | ||
expect(isPlainObject(undefined)).toBe(false); | ||
expect(isPlainObject(42)).toBe(false); | ||
expect(isPlainObject("foo")).toBe(false); | ||
expect(isPlainObject(true)).toBe(false); | ||
expect(isPlainObject(Symbol())).toBe(false); | ||
}); | ||
|
||
test("should return false for non-plain objects", () => { | ||
expect(isPlainObject([])).toBe(false); | ||
expect(isPlainObject(new Date())).toBe(false); | ||
expect(isPlainObject(/foo/)).toBe(false); | ||
expect( | ||
isPlainObject(() => { | ||
// noop | ||
}), | ||
).toBe(false); | ||
|
||
expect(isPlainObject(Object.prototype)).toBe(false); | ||
}); |
File renamed without changes.
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,33 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
import { createTson } from "./tson.js"; | ||
import { TsonType } from "./types.js"; | ||
|
||
test("multiple handlers for primitive string found", () => { | ||
const stringHandler: TsonType<string, never> = { | ||
primitive: "string", | ||
}; | ||
expect(() => { | ||
createTson({ | ||
types: [stringHandler, stringHandler], | ||
}); | ||
}).toThrowErrorMatchingInlineSnapshot( | ||
'"Multiple handlers for primitive string found"', | ||
); | ||
}); | ||
|
||
test("duplicate keys", () => { | ||
const stringHandler: TsonType<string, string> = { | ||
deserialize: (v) => v, | ||
key: "string", | ||
serialize: (v) => v, | ||
test: (v) => typeof v === "string", | ||
}; | ||
expect(() => { | ||
createTson({ | ||
types: [stringHandler, stringHandler], | ||
}); | ||
}).toThrowErrorMatchingInlineSnapshot( | ||
'"Multiple handlers for key string found"', | ||
); | ||
}); |
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