test: add tests for BaseError custom error
[e-mobility-charging-stations-simulator.git] / tests / exception / BaseError.test.ts
diff --git a/tests/exception/BaseError.test.ts b/tests/exception/BaseError.test.ts
new file mode 100644 (file)
index 0000000..947bac2
--- /dev/null
@@ -0,0 +1,24 @@
+import { describe, it } from 'node:test'
+
+import { expect } from 'expect'
+
+import { BaseError } from '../../src/exception/BaseError.js'
+
+await describe('BaseError test suite', async () => {
+  await it('Verify that BaseError can be instantiated', () => {
+    const baseError = new BaseError()
+    expect(baseError).toBeInstanceOf(BaseError)
+    expect(baseError.name).toBe('BaseError')
+    expect(baseError.message).toBe('')
+    expect(typeof baseError.stack === 'string').toBe(true)
+    expect(baseError.stack).not.toBe('')
+    expect(baseError.cause).toBeUndefined()
+    expect(baseError.date).toBeInstanceOf(Date)
+  })
+
+  await it('Verify that BaseError can be instantiated with a message', () => {
+    const baseError = new BaseError('Test message')
+    expect(baseError).toBeInstanceOf(BaseError)
+    expect(baseError.message).toBe('Test message')
+  })
+})