tinyexpect 0.5.1 → 0.6.1

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/README.md CHANGED
@@ -17,6 +17,13 @@
17
17
  - `toBeDefined()`: Verifies value is not undefined
18
18
  - `toContainString(str)`: Checks if string contains a substring
19
19
  - `toNotContainString(str)`: Checks if string does not contain a substring
20
+ - `toBeSameObject(value)`: Check objects, return true if different property order
21
+
22
+ ### Example
23
+ ```typescript
24
+ import { expect } from "tinyexpect"
25
+ expect("test").toBe("test")
26
+ ```
20
27
 
21
28
  ## Error Handling
22
29
 
@@ -27,4 +34,4 @@ All matchers throw descriptive errors when assertions fail, including:
27
34
 
28
35
  ## License
29
36
 
30
- MIT
37
+ MIT
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.expect = void 0;
3
+ exports.expect = expect;
4
4
  function expect(v) {
5
5
  return {
6
6
  toBe: (a) => {
@@ -72,14 +72,18 @@ function expect(v) {
72
72
  throw new Error(`${v} doesn't contain ${str}`);
73
73
  }
74
74
  },
75
- toNotContainString(str) {
76
- if (typeof v !== "string") {
77
- throw new Error(`${v} is not a string`);
75
+ toBeSameObject(obj) {
76
+ if (typeof v !== "object" || typeof obj !== "object") {
77
+ throw new Error(`Both values must be objects`);
78
78
  }
79
- if (v.includes(str)) {
80
- throw new Error(`${v} contains ${str}`);
79
+ const vKeys = Object.keys(v).sort();
80
+ const objKeys = Object.keys(obj).sort();
81
+ if (vKeys.length !== objKeys.length || vKeys.every((key, i) => key === objKeys[i])) {
82
+ throw new Error(`Object keys do not match`);
83
+ }
84
+ if (!vKeys.every(key => JSON.stringify(v[key]) === JSON.stringify(obj[key]))) {
85
+ throw new Error(`Object values do not match`);
81
86
  }
82
87
  }
83
88
  };
84
89
  }
85
- exports.expect = expect;
package/index.ts CHANGED
@@ -70,14 +70,20 @@ export function expect(v: any) {
70
70
  throw new Error(`${v} doesn't contain ${str}`)
71
71
  }
72
72
  },
73
- toNotContainString(str:string){
74
- if (typeof v !== "string"){
75
- throw new Error(`${v} is not a string`)
76
- }
73
+ toBeSameObject(obj:any){
74
+ if (typeof v !== "object" || typeof obj !== "object") {
75
+ throw new Error(`Both values must be objects`);
76
+ }
77
+
78
+ const vKeys = Object.keys(v).sort();
79
+ const objKeys = Object.keys(obj).sort();
77
80
 
78
- if ((v as string).includes(str)){
79
- throw new Error(`${v} contains ${str}`)
80
- }
81
- }
81
+ if (vKeys.length !== objKeys.length || vKeys.every((key, i) => key === objKeys[i])) {
82
+ throw new Error(`Object keys do not match`);
83
+ }
84
+ if (!vKeys.every(key => JSON.stringify(v[key]) === JSON.stringify(obj[key]))) {
85
+ throw new Error(`Object values do not match`);
86
+ }
87
+ }
82
88
  }
83
89
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinyexpect",
3
- "version": "0.5.1",
3
+ "version": "0.6.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {