Skip to content

Commit bbfc4a2

Browse files
Update assembly-line.spec.js
1 parent 45d7407 commit bbfc4a2

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

exercises/concept/assembly-line/assembly-line.spec.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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'
33
describe("isBoolean",() => {
44
test("isBoolean works on booleans",() => {
55
expect(isBoolean(true)).toBe(true)
@@ -41,6 +41,7 @@ class ClassForTesting {
4141
this.number = number;
4242
this.word = word;
4343
}
44+
id(){}
4445
}
4546
describe("isObject",() => {
4647
test("isObject works on objects",() => {
@@ -134,28 +135,34 @@ describe("isEmptyArray", () => {
134135
expect(isEmptyArray(123)).toBe(false);
135136
});
136137
});
137-
138+
class TestAssertHasId {
139+
id(){}
140+
}
138141
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", () => {
140143
expect(() => assertHasId({})).toThrow();
141144
});
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", () => {
143146
expect(() => assertHasId({ id: 1 })).not.toThrow();
147+
expect(() => assertHasId(new TestAssertHasId())).not.toThrow();
144148
});
145149
});
146-
150+
class TestHasType {
151+
type(){}
152+
}
147153
describe("hasType", () => {
148154
test("hasType works correctly", () => {
149155
expect(hasType({ type: 'example' })).toBe(true);
150156
expect(hasType({})).toBe(false);
157+
expect(hasType(new TestHasType())).toBe(true)
151158
});
152159
});
153160

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);
159166

160167
});
161168
});

0 commit comments

Comments
 (0)