Skip to content

Commit 6c3f921

Browse files
darindvmutafov
authored andcommitted
fix: JSONObject tests should not rely on magic strings (#1500) (#1507)
1 parent 0117448 commit 6c3f921

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

test-app/app/src/main/assets/app/tests/testJSONObjects.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ describe("Test JSONObject conversions", () => {
4242
};
4343
let actual = org.json.JSONObject.from(param);
4444
expect(actual instanceof org.json.JSONObject).toBe(true);
45-
let actualStr = com.tns.tests.JSONObjectMethods.testWithObject(actual);
46-
expect(actualStr).toBe(`{"prop1":"prop1 value","prop2":123,"prop3":{"prop4":"prop 4 value"}}`);
45+
expect(actual.getString("prop1")).toEqual(param.prop1);
46+
expect(actual.getInt("prop2")).toEqual(param.prop2);
47+
expect(actual.getJSONObject("prop3").getString("prop4")).toEqual(param.prop3.prop4);
4748
});
4849

4950
it("JSONObject.from with array", () => {
@@ -56,7 +57,10 @@ describe("Test JSONObject conversions", () => {
5657
}];
5758
let actual = org.json.JSONObject.from(param);
5859
expect(actual instanceof org.json.JSONArray).toBe(true);
59-
let actualStr = com.tns.tests.JSONObjectMethods.testWithArray(actual);
60-
expect(actualStr).toBe(`[{"prop1":"item 1, prop1 value","prop2":123},{"prop1":"item 2, prop1 value","prop2":456}]`);
60+
expect(actual.length()).toEqual(2);
61+
for (var i = 0; i < actual.length(); i++) {
62+
expect(actual.get(i).getString("prop1")).toEqual(param[i].prop1);
63+
expect(actual.get(i).getInt("prop2")).toEqual(param[i].prop2);
64+
}
6165
});
6266
});

test-app/app/src/main/java/com/tns/tests/JSONObjectMethods.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)