2020-07-05 17:26:26 -07:00
|
|
|
test("iterate through empty string", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
const a = [];
|
|
|
|
|
for (const property in "") {
|
|
|
|
|
a.push(property);
|
|
|
|
|
}
|
|
|
|
|
expect(a).toEqual([]);
|
2020-07-05 17:26:26 -07:00
|
|
|
});
|
2020-04-21 19:21:26 +01:00
|
|
|
|
2020-07-05 17:26:26 -07:00
|
|
|
test("iterate through number", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
const a = [];
|
|
|
|
|
for (const property in 123) {
|
|
|
|
|
a.push(property);
|
|
|
|
|
}
|
|
|
|
|
expect(a).toEqual([]);
|
2020-07-05 17:26:26 -07:00
|
|
|
});
|
2020-04-21 19:21:26 +01:00
|
|
|
|
2020-07-05 17:26:26 -07:00
|
|
|
test("iterate through empty object", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
const a = [];
|
|
|
|
|
for (const property in {}) {
|
|
|
|
|
a.push(property);
|
|
|
|
|
}
|
|
|
|
|
expect(a).toEqual([]);
|
2020-07-05 17:26:26 -07:00
|
|
|
});
|
2020-04-21 19:21:26 +01:00
|
|
|
|
2020-07-05 17:26:26 -07:00
|
|
|
test("iterate through string", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
const a = [];
|
|
|
|
|
for (const property in "hello") {
|
|
|
|
|
a.push(property);
|
|
|
|
|
}
|
|
|
|
|
expect(a).toEqual(["0", "1", "2", "3", "4"]);
|
2020-07-05 17:26:26 -07:00
|
|
|
});
|
2020-04-21 19:21:26 +01:00
|
|
|
|
2020-07-05 17:26:26 -07:00
|
|
|
test("iterate through object", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
const a = [];
|
|
|
|
|
for (const property in { a: 1, b: 2, c: 2 }) {
|
|
|
|
|
a.push(property);
|
|
|
|
|
}
|
|
|
|
|
expect(a).toEqual(["a", "b", "c"]);
|
2020-07-05 17:26:26 -07:00
|
|
|
});
|
2020-04-21 19:21:26 +01:00
|
|
|
|
2020-07-05 17:26:26 -07:00
|
|
|
test("use already-declared variable", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
var property;
|
|
|
|
|
for (property in "abc");
|
|
|
|
|
expect(property).toBe("2");
|
2020-07-05 17:26:26 -07:00
|
|
|
});
|