resourcerer 2.0.6 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import { Utils } from "../index";
2
2
  import {
3
+ getNestedValue,
3
4
  hasErrored,
4
5
  hasLoaded,
5
6
  isDeepEqual,
@@ -186,7 +187,7 @@ describe("Utils", () => {
186
187
 
187
188
  it("if the objects have equal values, deeply", () => {
188
189
  expect(
189
- isDeepEqual({ one: "one", two: 2, three: null }, { one: "one", two: 2, three: null })
190
+ isDeepEqual({ one: "one", two: 2, three: null }, { one: "one", two: 2, three: null }),
190
191
  ).toBe(true);
191
192
  // nested
192
193
  expect(
@@ -198,8 +199,8 @@ describe("Utils", () => {
198
199
  {
199
200
  one: "one",
200
201
  two: { three: "three" },
201
- }
202
- )
202
+ },
203
+ ),
203
204
  ).toBe(true);
204
205
  });
205
206
  });
@@ -236,8 +237,8 @@ describe("Utils", () => {
236
237
  { name: "zorah" },
237
238
  { name: "alex" },
238
239
  ],
239
- ({ name }) => name
240
- )
240
+ ({ name }) => name,
241
+ ),
241
242
  ).toEqual([
242
243
  { name: "alex" },
243
244
  { name: "alex" },
@@ -252,4 +253,20 @@ describe("Utils", () => {
252
253
  expect(sortBy()).toEqual([]);
253
254
  });
254
255
  });
256
+
257
+ describe("getNestedValue", () => {
258
+ it("gets a nested value from an object", () => {
259
+ expect(getNestedValue({ foo: { bar: "baz" } }, "foo.bar")).toEqual("baz");
260
+ expect(getNestedValue({ foo: "bar" }, "foo")).toEqual("bar");
261
+ });
262
+
263
+ it("returns undefined if the path is not found", () => {
264
+ expect(getNestedValue({ foo: { bar: "baz" } }, "foo.baz")).toBeUndefined();
265
+ });
266
+
267
+ it("returns undefined if the object is not an object", () => {
268
+ // this wouldn't pass types...
269
+ expect(getNestedValue(null, "foo.bar")).toBeUndefined();
270
+ });
271
+ });
255
272
  });