forked from smithy-lang/smithy-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(smithy-client): string.toString requires this be a String (smithy…
…-lang#1027) * fix(smithy-client): string.toString requires this be a String Because of Because of microsoft/tslib#95, TS 'extends' shim doesn't support extending native types like String. So here we create StringWrapper that duplicate everything from String class including its prototype chain. So we can extend from here. * fix: typo
- Loading branch information
1 parent
cc0e87e
commit 5db1522
Showing
2 changed files
with
69 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { LazyJsonString } from "./lazy-json"; | ||
describe("LazyJsonString", () => { | ||
it("should has string methods", () => { | ||
const jsonValue = new LazyJsonString('"foo"'); | ||
expect(jsonValue.length).toBe(5); | ||
expect(jsonValue.toString()).toBe('"foo"'); | ||
}); | ||
|
||
it("should deserialize json properly", () => { | ||
const jsonValue = new LazyJsonString('"foo"'); | ||
expect(jsonValue.deserializeJSON()).toBe("foo"); | ||
const wrongJsonValue = new LazyJsonString("foo"); | ||
expect(() => wrongJsonValue.deserializeJSON()).toThrow(); | ||
}); | ||
|
||
it("should get JSON string properly", () => { | ||
const jsonValue = new LazyJsonString('{"foo", "bar"}'); | ||
expect(jsonValue.toJSON()).toBe('{"foo", "bar"}'); | ||
}); | ||
|
||
it("can instantiate from LazyJsonString class", () => { | ||
const original = new LazyJsonString('"foo"'); | ||
const newOne = LazyJsonString.fromObject(original); | ||
expect(newOne.toString()).toBe('"foo"'); | ||
}); | ||
|
||
it("can instantiate from String class", () => { | ||
const jsonValue = LazyJsonString.fromObject(new String('"foo"')); | ||
expect(jsonValue.toString()).toBe('"foo"'); | ||
}); | ||
|
||
it("can instantiate from object", () => { | ||
const jsonValue = LazyJsonString.fromObject({ foo: "bar" }); | ||
expect(jsonValue.toString()).toBe('{"foo":"bar"}'); | ||
}); | ||
}); |
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