Skip to content

Commit a58ebee

Browse files
authored
chore: use expectTypeOf in tests (#131)
1 parent 5b5dbb9 commit a58ebee

4 files changed

Lines changed: 19 additions & 19 deletions

File tree

backend/tests/db.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, test, expect, afterEach, beforeEach } from 'bun:test'
1+
import { describe, test, expect, expectTypeOf, afterEach, beforeEach } from 'bun:test'
22
import { closeDb, getDb, initializeDb } from '@backend/plugins/database'
33

44
describe('Database', () => {
@@ -10,7 +10,7 @@ describe('Database', () => {
1010
test('should initialize database successfully', async () => {
1111
const db = await initializeDb(':memory:')
1212
expect(db).toBeDefined()
13-
expect(typeof db.run).toBe('function')
13+
expectTypeOf(db.run).toBeFunction()
1414
})
1515

1616
test('getDb should return a database connection', async () => {
@@ -22,7 +22,7 @@ describe('Database', () => {
2222

2323
// Verify the connection exists and has the expected methods
2424
expect(db).toBeDefined()
25-
expect(typeof db.run).toBe('function')
25+
expectTypeOf(db.run).toBeFunction()
2626
})
2727

2828
test('getDb should throw if database is not initialized', () => {
@@ -64,7 +64,7 @@ describe('Database', () => {
6464
// Should be able to initialize again
6565
const db = await initializeDb(':memory:')
6666
expect(db).toBeDefined()
67-
expect(typeof db.run).toBe('function')
67+
expectTypeOf(db.run).toBeFunction()
6868
})
6969
})
7070
})

frontend/src/features/wikibase-schema/composables/__tests__/useSchemaApi.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe('useSchemaApi', () => {
9494
setActivePinia(
9595
createTestingPinia({
9696
createSpy: mock,
97-
stubActions: true, // Stub actions since we're testing the composable, not the store
97+
stubActions: false, // Allow actions to work so store state gets updated
9898
}),
9999
)
100100

frontend/src/features/wikibase-schema/stores/__tests__/schema.store.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, beforeEach, mock } from 'bun:test'
1+
import { describe, it, expect, expectTypeOf, beforeEach, mock } from 'bun:test'
22
import { createTestingPinia } from '@pinia/testing'
33
import { setActivePinia } from 'pinia'
44
import { useSchemaStore } from '@frontend/features/wikibase-schema/stores/schema.store'
@@ -634,7 +634,7 @@ describe('useSchemaStore', () => {
634634
store.addStatement(property, valueMapping)
635635

636636
expect(store.statements[0]?.id).toBeDefined()
637-
expect(typeof store.statements[0]?.id).toBe('string')
637+
expectTypeOf(store.statements[0]!.id).toBeString()
638638
})
639639

640640
it('should create statement with property object', () => {
@@ -652,7 +652,7 @@ describe('useSchemaStore', () => {
652652
store.addStatement(property, valueMapping)
653653

654654
expect(store.statements[0]?.property).toBeDefined()
655-
expect(typeof store.statements[0]?.property).toBe('object')
655+
expectTypeOf(store.statements[0]!.property).toBeObject()
656656
})
657657

658658
it('should create statement with value object', () => {
@@ -670,7 +670,7 @@ describe('useSchemaStore', () => {
670670
store.addStatement(property, valueMapping)
671671

672672
expect(store.statements[0]?.value).toBeDefined()
673-
expect(typeof store.statements[0]?.value).toBe('object')
673+
expectTypeOf(store.statements[0]!.value).toBeObject()
674674
})
675675

676676
it('should create statement with default normal rank', () => {

frontend/src/shared/composables/__tests__/useDragDropContext.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, beforeEach } from 'bun:test'
1+
import { describe, it, expect, expectTypeOf, beforeEach } from 'bun:test'
22
import { createPinia, setActivePinia } from 'pinia'
33
import { useDragDropContext } from '@frontend/shared/composables/useDragDropContext'
44
import { useDragDropStore } from '@frontend/features/data-processing/stores/drag-drop.store'
@@ -267,18 +267,18 @@ describe('useDragDropContext', () => {
267267
const context = useDragDropContext()
268268

269269
// Test that all expected methods exist
270-
expect(typeof context.startDrag).toBe('function')
271-
expect(typeof context.endDrag).toBe('function')
272-
expect(typeof context.enterDropZone).toBe('function')
273-
expect(typeof context.leaveDropZone).toBe('function')
274-
expect(typeof context.validateDrop).toBe('function')
275-
expect(typeof context.performDrop).toBe('function')
276-
expect(typeof context.createDropZoneConfig).toBe('function')
270+
expectTypeOf(context.startDrag).toBeFunction()
271+
expectTypeOf(context.endDrag).toBeFunction()
272+
expectTypeOf(context.enterDropZone).toBeFunction()
273+
expectTypeOf(context.leaveDropZone).toBeFunction()
274+
expectTypeOf(context.validateDrop).toBeFunction()
275+
expectTypeOf(context.performDrop).toBeFunction()
276+
expectTypeOf(context.createDropZoneConfig).toBeFunction()
277277
})
278278

279279
it('should work with store setAvailableTargets method', () => {
280280
const store = useDragDropStore()
281-
expect(typeof store.setAvailableTargets).toBe('function')
281+
expectTypeOf(store.setAvailableTargets).toBeFunction()
282282

283283
const targets = [mockDropTarget]
284284
store.setAvailableTargets(targets)
@@ -289,7 +289,7 @@ describe('useDragDropContext', () => {
289289

290290
it('should work with store getValidTargetsForColumn method', () => {
291291
const store = useDragDropStore()
292-
expect(typeof store.getValidTargetsForColumn).toBe('function')
292+
expectTypeOf(store.getValidTargetsForColumn).toBeFunction()
293293

294294
store.setAvailableTargets([mockDropTarget])
295295
const validTargets = store.getValidTargetsForColumn(mockColumnInfo)

0 commit comments

Comments
 (0)