|
1 | 1 | import { describe, expect, test } from '@jest/globals'; |
2 | | -import { isBoolean, isNumber, isObject, isNumericString, ElectronicDevice, isElectronic, isNonEmptyArray, isEmptyArray , assertHasId, hasType, hasConstructorProperty, hasDefinedType} from './assembly-line' |
| 2 | +import { isBoolean, isNumber, isObject, isNumericString, ElectronicDevice, isElectronic, isNonEmptyArray, isEmptyArray , assertHasId, hasType, hasIdProperty, hasDefinedType} from './assembly-line' |
3 | 3 | describe("isBoolean",() => { |
4 | 4 | test("isBoolean works on booleans",() => { |
5 | 5 | expect(isBoolean(true)).toBe(true) |
@@ -41,6 +41,7 @@ class ClassForTesting { |
41 | 41 | this.number = number; |
42 | 42 | this.word = word; |
43 | 43 | } |
| 44 | + id(){} |
44 | 45 | } |
45 | 46 | describe("isObject",() => { |
46 | 47 | test("isObject works on objects",() => { |
@@ -134,28 +135,34 @@ describe("isEmptyArray", () => { |
134 | 135 | expect(isEmptyArray(123)).toBe(false); |
135 | 136 | }); |
136 | 137 | }); |
137 | | - |
| 138 | +class TestAssertHasId { |
| 139 | + id(){} |
| 140 | +} |
138 | 141 | describe("assertHasId", () => { |
139 | | - test("assertHasId throws error if object has no 'id' property", () => { |
| 142 | + test("assertHasId throws error if object has no 'id' property or method", () => { |
140 | 143 | expect(() => assertHasId({})).toThrow(); |
141 | 144 | }); |
142 | | - test("assertHasId does not throw error if object has 'id' property", () => { |
| 145 | + test("assertHasId does not throw error if object has 'id' property or method", () => { |
143 | 146 | expect(() => assertHasId({ id: 1 })).not.toThrow(); |
| 147 | + expect(() => assertHasId(new TestAssertHasId())).not.toThrow(); |
144 | 148 | }); |
145 | 149 | }); |
146 | | - |
| 150 | +class TestHasType { |
| 151 | + type(){} |
| 152 | +} |
147 | 153 | describe("hasType", () => { |
148 | 154 | test("hasType works correctly", () => { |
149 | 155 | expect(hasType({ type: 'example' })).toBe(true); |
150 | 156 | expect(hasType({})).toBe(false); |
| 157 | + expect(hasType(new TestHasType())).toBe(true) |
151 | 158 | }); |
152 | 159 | }); |
153 | 160 |
|
154 | | -describe("hasConstructorProperty", () => { |
155 | | - test("hasConstructorProperty works correctly", () => { |
156 | | - expect(hasConstructorProperty({ constructor: 'test' })).toBe(true); |
157 | | - expect(hasConstructorProperty({})).toBe(false); |
158 | | - expect(hasConstructorProperty(new ClassForTesting)).toBe(false); |
| 161 | +describe("hasIdProperty", () => { |
| 162 | + test("hasIdProperty works correctly", () => { |
| 163 | + expect(hasIdProperty({ id: 'test' })).toBe(true); |
| 164 | + expect(hasIdProperty({})).toBe(false); |
| 165 | + expect(hasIdProperty(new ClassForTesting())).toBe(false); |
159 | 166 |
|
160 | 167 | }); |
161 | 168 | }); |
|
0 commit comments