Skip to content

Commit

Permalink
chore: Add JSON.parse test case. (#263)
Browse files Browse the repository at this point in the history
* chore: Add JSON.parse test case.

* Add an 'as' to show the direct casting intent.
  • Loading branch information
stephenh authored Apr 5, 2021
1 parent f40a4c3 commit 51e5386
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions integration/use-date-string/use-date-string-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,24 @@ describe('useDate=string', () => {
}
`);
});

it('supports using JSON.parse directly', () => {
// Given a message that is encoded to json by the server
const t1: Todo = {
id: '6883ed6e-bd0d-4817-ba58-c2a53c73edc2',
timestamp: feb1.toISOString(),
repeatedTimestamp: [jan1.toISOString(), feb1.toISOString()],
mapOfTimestamps: {
jan1: jan1.toISOString(),
feb1: feb1.toISOString(),
},
};
const json = JSON.stringify(t1);

// The client-side can JSON.parse it
const t2 = JSON.parse(json) as Todo;

// And they'll be the same
expect(t2).toEqual(t1);
});
});

0 comments on commit 51e5386

Please sign in to comment.