Skip to content

Commit 40b69f7

Browse files
authored
Use ! to simplify test logic (#354)
1 parent bcb5f4c commit 40b69f7

File tree

1 file changed

+21
-36
lines changed

1 file changed

+21
-36
lines changed

src/collections/vectors/journey.test.ts

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-non-null-assertion */
22
/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
33
import { requireAtLeast } from '../../../test/version.js';
4-
import weaviate, {
5-
VectorIndexConfigHNSW,
6-
WeaviateClient,
7-
WeaviateField,
8-
WeaviateGenericObject,
9-
} from '../../index.js';
4+
import weaviate, { VectorIndexConfigHNSW, WeaviateClient } from '../../index.js';
105
import { Collection } from '../collection/index.js';
116
import { MultiVectorType, SingleVectorType } from '../query/types.js';
127

@@ -78,40 +73,30 @@ requireAtLeast(1, 29, 0).describe(
7873

7974
it('should be able to get the inserted object with its vectors stated implicitly', async () => {
8075
const obj = await collection.query.fetchObjectById(id1, { includeVector: true });
81-
const assert = (obj: any): obj is WeaviateGenericObject<Record<string, WeaviateField>, MyVectors> => {
82-
expect(obj).not.toBeNull();
83-
return true;
84-
};
85-
if (assert(obj)) {
86-
singleVector = obj.vectors.regular;
87-
multiVector = obj.vectors.colbert;
88-
expect(obj.uuid).toBe(id1);
89-
expect(obj.vectors).toBeDefined();
90-
expect(obj.vectors.regular).toEqual([1, 2, 3, 4]);
91-
expect(obj.vectors.colbert).toEqual([
92-
[1, 2],
93-
[3, 4],
94-
]);
95-
}
76+
expect(obj).not.toBeNull();
77+
singleVector = obj!.vectors.regular;
78+
multiVector = obj!.vectors.colbert;
79+
expect(obj!.uuid).toBe(id1);
80+
expect(obj!.vectors).toBeDefined();
81+
expect(obj!.vectors.regular).toEqual([1, 2, 3, 4]);
82+
expect(obj!.vectors.colbert).toEqual([
83+
[1, 2],
84+
[3, 4],
85+
]);
9686
});
9787

9888
it('should be able to get the inserted object with its vectors stated explicitly', async () => {
9989
const obj = await collection.query.fetchObjectById(id1, { includeVector: ['regular', 'colbert'] });
100-
const assert = (obj: any): obj is WeaviateGenericObject<Record<string, WeaviateField>, MyVectors> => {
101-
expect(obj).not.toBeNull();
102-
return true;
103-
};
104-
if (assert(obj)) {
105-
singleVector = obj.vectors.regular;
106-
multiVector = obj.vectors.colbert;
107-
expect(obj.uuid).toBe(id1);
108-
expect(obj.vectors).toBeDefined();
109-
expect(obj.vectors.regular).toEqual([1, 2, 3, 4]);
110-
expect(obj.vectors.colbert).toEqual([
111-
[1, 2],
112-
[3, 4],
113-
]);
114-
}
90+
expect(obj).not.toBeNull();
91+
singleVector = obj!.vectors.regular;
92+
multiVector = obj!.vectors.colbert;
93+
expect(obj!.uuid).toBe(id1);
94+
expect(obj!.vectors).toBeDefined();
95+
expect(obj!.vectors.regular).toEqual([1, 2, 3, 4]);
96+
expect(obj!.vectors.colbert).toEqual([
97+
[1, 2],
98+
[3, 4],
99+
]);
115100
});
116101

117102
it('should be able to get the inserted object with one of its vectors', async () => {

0 commit comments

Comments
 (0)