Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] [TS migration] Migrate 'sanitizeStringForJSONParseTest.js' test to TypeScript #36026

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import sanitizeStringForJSONParse from '../../.github/libs/sanitizeStringForJSONParse';

// Bad inputs should cause an error to be thrown
const badInputs = [null, undefined, 42, true];
const badInputs: Array<null | undefined | number | boolean> = [null, undefined, 42, true];

// Invalid JSON Data should be able to get parsed and the parsed result should match the input text.
const invalidJSONData = [
const invalidJSONData: Array<[string, string]> = [
['Hello \t world!', 'Hello \t world!'],
['Hello \n world!', 'Hello \n world!'],
['Hello \n\tworld!', 'Hello \n\tworld!'],
Expand All @@ -21,7 +21,7 @@ const invalidJSONData = [
];

// Valid JSON Data should be able to get parsed and the input text should be unmodified.
const validJSONData = [
const validJSONData: Array<[string, string]> = [
['', ''],
['Hello world!', 'Hello world!'],
['Hello\\\\world!', 'Hello\\\\world!'],
Expand All @@ -30,13 +30,15 @@ const validJSONData = [
describe('santizeStringForJSONParse', () => {
describe.each(badInputs)('willDetectBadInputs', (input) => {
test('sanitizeStringForJSONParse', () => {
// @ts-expect-error TODO: Remove this once sanitizeStringForJSONParse (https://github.com/Expensify/App/issues/25360) is migrated to TypeScript.
expect(() => sanitizeStringForJSONParse(input)).toThrow();
});
});

describe.each(invalidJSONData)('canHandleInvalidJSON', (input, expectedOutput) => {
test('sanitizeStringForJSONParse', () => {
const badJSON = `{"key": "${input}"}`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-return -- it's supposed to throw an error
expect(() => JSON.parse(badJSON)).toThrow();
const goodJSON = JSON.parse(`{"key": "${sanitizeStringForJSONParse(input)}"}`);
expect(goodJSON.key).toStrictEqual(expectedOutput);
Expand Down
Loading