@tim-code/my-util 0.1.1 → 0.1.2
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/package.json +1 -1
- package/src/object.js +1 -1
- package/src/object.test.js +8 -8
package/package.json
CHANGED
package/src/object.js
CHANGED
package/src/object.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-restricted-syntax */
|
|
2
2
|
import { jest } from "@jest/globals"
|
|
3
|
-
import {
|
|
3
|
+
import { deleteUndefinedValues, like, mutateValues, via } from "./object.js"
|
|
4
4
|
|
|
5
5
|
describe("mutateValues", () => {
|
|
6
6
|
it("mutates values in the object using the callback", () => {
|
|
@@ -106,14 +106,14 @@ describe("via", () => {
|
|
|
106
106
|
describe("contains", () => {
|
|
107
107
|
it("returns true when object contains all template keys with same values", () => {
|
|
108
108
|
const template = { a: 1, b: 2 }
|
|
109
|
-
const fn =
|
|
109
|
+
const fn = like(template)
|
|
110
110
|
expect(fn({ a: 1, b: 2, c: 3 })).toBe(true)
|
|
111
111
|
expect(fn({ a: 1, b: 2 })).toBe(true)
|
|
112
112
|
})
|
|
113
113
|
|
|
114
114
|
it("returns false if any template key is missing", () => {
|
|
115
115
|
const template = { a: 1, b: 2 }
|
|
116
|
-
const fn =
|
|
116
|
+
const fn = like(template)
|
|
117
117
|
expect(fn({ a: 1 })).toBe(false)
|
|
118
118
|
expect(fn({ b: 2 })).toBe(false)
|
|
119
119
|
expect(fn({})).toBe(false)
|
|
@@ -121,14 +121,14 @@ describe("contains", () => {
|
|
|
121
121
|
|
|
122
122
|
it("returns false if any template key has a different value", () => {
|
|
123
123
|
const template = { a: 1, b: 2 }
|
|
124
|
-
const fn =
|
|
124
|
+
const fn = like(template)
|
|
125
125
|
expect(fn({ a: 1, b: 3 })).toBe(false)
|
|
126
126
|
expect(fn({ a: 2, b: 2 })).toBe(false)
|
|
127
127
|
expect(fn({ a: 2, b: 3 })).toBe(false)
|
|
128
128
|
})
|
|
129
129
|
|
|
130
130
|
it("works with empty template (always true)", () => {
|
|
131
|
-
const fn =
|
|
131
|
+
const fn = like({})
|
|
132
132
|
expect(fn({})).toBe(true)
|
|
133
133
|
expect(fn({ a: 1 })).toBe(true)
|
|
134
134
|
expect(fn({ a: undefined })).toBe(true)
|
|
@@ -136,13 +136,13 @@ describe("contains", () => {
|
|
|
136
136
|
|
|
137
137
|
it("does not require object to have only template keys", () => {
|
|
138
138
|
const template = { x: 5 }
|
|
139
|
-
const fn =
|
|
139
|
+
const fn = like(template)
|
|
140
140
|
expect(fn({ x: 5, y: 10 })).toBe(true)
|
|
141
141
|
})
|
|
142
142
|
|
|
143
143
|
it("uses strict equality (===) for comparison", () => {
|
|
144
144
|
const template = { a: 0 }
|
|
145
|
-
const fn =
|
|
145
|
+
const fn = like(template)
|
|
146
146
|
expect(fn({ a: false })).toBe(false)
|
|
147
147
|
expect(fn({ a: "0" })).toBe(false)
|
|
148
148
|
expect(fn({ a: 0 })).toBe(true)
|
|
@@ -151,7 +151,7 @@ describe("contains", () => {
|
|
|
151
151
|
// ISSUE: contains() does not check for own properties only; it will match inherited properties.
|
|
152
152
|
it("matches inherited properties in the object", () => {
|
|
153
153
|
const template = { foo: 1 }
|
|
154
|
-
const fn =
|
|
154
|
+
const fn = like(template)
|
|
155
155
|
const proto = { foo: 1 }
|
|
156
156
|
const obj = Object.create(proto)
|
|
157
157
|
expect(fn(obj)).toBe(true)
|