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.
- package/build/index.d.ts +2 -1
- package/build/index.js +1 -0
- package/build/lib/canonical-model-cache.d.ts +8 -0
- package/build/lib/canonical-model-cache.js +24 -0
- package/build/lib/canonical-model.d.ts +14 -0
- package/build/lib/canonical-model.js +33 -0
- package/build/lib/collection.d.ts +2 -1
- package/build/lib/collection.js +4 -0
- package/build/lib/events.d.ts +7 -7
- package/build/lib/events.js +2 -2
- package/build/lib/model-cache.d.ts +1 -0
- package/build/lib/model-cache.js +1 -0
- package/build/lib/model.d.ts +16 -3
- package/build/lib/model.js +55 -3
- package/build/lib/request.d.ts +1 -0
- package/build/lib/resourcerer.js +1 -1
- package/build/lib/sync.js +3 -2
- package/build/lib/types.d.ts +3 -0
- package/build/lib/utils.d.ts +1 -0
- package/build/lib/utils.js +3 -0
- package/package.json +1 -1
- package/test/canonical-model-cache.test.js +75 -0
- package/test/canonical-model.test.js +87 -0
- package/test/collection.test.js +16 -2
- package/test/events.test.js +83 -0
- package/test/model-cache.test.js +30 -24
- package/test/model.test.js +358 -1
- package/test/sync.test.js +10 -0
- package/test/utils.test.js +22 -5
package/test/utils.test.js
CHANGED
|
@@ -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
|
});
|