tinyexpect 0.1.1 → 0.2.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/.gitattributes CHANGED
File without changes
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
@@ -1,2 +1,3 @@
1
1
  # tinyexpect
2
2
 
3
+ `expect` 0 dependencies.
package/index.js CHANGED
@@ -4,19 +4,18 @@ exports.expect = void 0;
4
4
  function expect(v) {
5
5
  return {
6
6
  toBe: (a) => {
7
- if (v !== a) {
7
+ if (typeof v === "object") {
8
+ if (JSON.stringify(v) !== JSON.stringify(a)) {
9
+ console.error(`Expected ${JSON.stringify(v, null, 2)} to be ${JSON.stringify(a, null, 2)}`);
10
+ throw new Error(`Objects are not equal`);
11
+ }
12
+ }
13
+ else if (v !== a) {
8
14
  throw new Error(`Expected ${v} to be ${a}`);
9
15
  }
10
16
  },
11
17
  eitherOr: (values) => {
12
- let result = false;
13
- for (let value of values) {
14
- if (v === value) {
15
- result = true;
16
- break;
17
- }
18
- }
19
- if (result === false) {
18
+ if (!values.includes(v)) {
20
19
  throw new Error(`Expected ${v} to be either of the following values:` +
21
20
  JSON.stringify(values));
22
21
  }
@@ -39,6 +38,21 @@ function expect(v) {
39
38
  return;
40
39
  }
41
40
  expect(v).toBeNumberOrParsed();
41
+ },
42
+ toBeFalsy() {
43
+ if (v) {
44
+ throw new Error(`${v} is not falsy`);
45
+ }
46
+ },
47
+ toBeTruthy() {
48
+ if (!v) {
49
+ throw new Error(`${v} is not truthy`);
50
+ }
51
+ },
52
+ toBeDefined() {
53
+ if (typeof v === "undefined") {
54
+ throw new Error(`${v} is not defined`);
55
+ }
42
56
  }
43
57
  };
44
58
  }
package/index.ts CHANGED
@@ -1,19 +1,17 @@
1
1
  export function expect(v: any) {
2
2
  return {
3
3
  toBe: (a: any) => {
4
- if (v !== a) {
5
- throw new Error(`Expected ${v} to be ${a}`)
6
- }
4
+ if (typeof v === "object") {
5
+ if (JSON.stringify(v) !== JSON.stringify(a)) {
6
+ console.error(`Expected ${JSON.stringify(v,null,2)} to be ${JSON.stringify(a,null,2)}`);
7
+ throw new Error(`Objects are not equal`);
8
+ }
9
+ } else if (v !== a) {
10
+ throw new Error(`Expected ${v} to be ${a}`);
11
+ }
7
12
  },
8
13
  eitherOr: (values: any[]) => {
9
- let result = false
10
- for (let value of values) {
11
- if (v === value) {
12
- result = true
13
- break
14
- }
15
- }
16
- if (result === false) {
14
+ if (!values.includes(v)) {
17
15
  throw new Error(
18
16
  `Expected ${v} to be either of the following values:` +
19
17
  JSON.stringify(values)
@@ -38,6 +36,21 @@ export function expect(v: any) {
38
36
  return
39
37
  }
40
38
  expect(v).toBeNumberOrParsed()
39
+ },
40
+ toBeFalsy(){
41
+ if (v){
42
+ throw new Error(`${v} is not falsy`)
43
+ }
44
+ },
45
+ toBeTruthy(){
46
+ if (!v){
47
+ throw new Error(`${v} is not truthy`)
48
+ }
49
+ },
50
+ toBeDefined(){
51
+ if (typeof v === "undefined"){
52
+ throw new Error(`${v} is not defined`)
53
+ }
41
54
  }
42
55
  }
43
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinyexpect",
3
- "version": "0.1.1",
3
+ "version": "0.2.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -13,7 +13,7 @@
13
13
  "keywords": [
14
14
  "expect"
15
15
  ],
16
- "author": "Mak Drakos",
16
+ "author": "crafter999",
17
17
  "license": "MIT",
18
18
  "bugs": {
19
19
  "url": "https://github.com/crafter999/tinyexpect/issues"
package/tsconfig.json CHANGED
File without changes