Skip to content

Commit db46746

Browse files
committed
test(framework-integration): fix error message assertion
DeepkitError now includes error code and docs URL in message. Use toContain() instead of toBe() for message matching.
1 parent fcdb059 commit db46746

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

packages/framework-integration/tests/controller-basic.spec.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { afterAll, expect, jest, test } from '@jest/globals';
2-
import { ClientProgress, JSONError, rpc } from '@deepkit/rpc';
3-
import { appModuleForControllers, closeAllCreatedServers, createServerClientPair, subscribeAndWait } from './util.js';
2+
import { fail } from 'assert';
43
import { Observable } from 'rxjs';
54
import { bufferCount, first, skip } from 'rxjs/operators';
6-
import { ObserverTimer } from '@deepkit/core-rxjs';
7-
import { isArray } from '@deepkit/core';
8-
import { fail } from 'assert';
95
import ws from 'ws';
10-
import { entity, ValidationError, ValidationErrorItem } from '@deepkit/type';
6+
7+
import { isArray } from '@deepkit/core';
8+
import { ObserverTimer } from '@deepkit/core-rxjs';
9+
import { ClientProgress, JSONError, rpc } from '@deepkit/rpc';
10+
import { ValidationError, ValidationErrorItem, entity } from '@deepkit/type';
11+
12+
import { appModuleForControllers, closeAllCreatedServers, createServerClientPair, subscribeAndWait } from './util.js';
1113

1214
// @ts-ignore
1315
global['WebSocket'] = ws;
@@ -29,9 +31,7 @@ class User {
2931
class MyCustomError {
3032
additional?: string;
3133

32-
constructor(public readonly message: string) {
33-
34-
}
34+
constructor(public readonly message: string) {}
3535
}
3636

3737
test('basic setup and methods', async () => {
@@ -65,8 +65,7 @@ test('basic setup and methods', async () => {
6565
}
6666

6767
@rpc.action()
68-
validationError(user: User) {
69-
}
68+
validationError(user: User) {}
7069
}
7170

7271
const { client, close } = await createServerClientPair('basic setup and methods', appModuleForControllers([TestController]));
@@ -82,7 +81,7 @@ test('basic setup and methods', async () => {
8281
fail('should error');
8382
} catch (error: any) {
8483
expect(error).toBeInstanceOf(Error);
85-
expect(error.message).toBe('Nothing to see here');
84+
expect(error.message).toContain('Nothing to see here');
8685
}
8786
}
8887

@@ -146,13 +145,13 @@ test('basic serialisation return: entity', async () => {
146145
}
147146

148147
@rpc.action()
149-
async allowPlainObject(name: string): Promise<{ mowla: boolean, name: string, date: Date }> {
148+
async allowPlainObject(name: string): Promise<{ mowla: boolean; name: string; date: Date }> {
150149
return { mowla: true, name, date: new Date('1987-12-12T11:00:00.000Z') };
151150
}
152151

153152
@rpc.action()
154153
async observable(name: string): Promise<Observable<User>> {
155-
return new Observable((observer) => {
154+
return new Observable(observer => {
156155
observer.next(new User(name));
157156
});
158157
}
@@ -182,7 +181,6 @@ test('basic serialisation return: entity', async () => {
182181
expect(struct.date).toBeInstanceOf(Date);
183182
expect(struct.date).toEqual(new Date('1987-12-12T11:00:00.000Z'));
184183

185-
186184
{
187185
const o = await controller.observable('peter');
188186
expect(o).toBeInstanceOf(Observable);
@@ -234,7 +232,7 @@ test('basic serialisation partial param: entity', async () => {
234232
getPartialUser(name?: string, date?: Date): Partial<User> {
235233
return {
236234
name: name,
237-
date: date
235+
date: date,
238236
};
239237
}
240238

@@ -248,14 +246,14 @@ test('basic serialisation partial param: entity', async () => {
248246

249247
const controller = client.controller<TestController>('test');
250248

251-
expect(await controller.passUser({name: 'asd'})).toEqual({name: 'asd'});
249+
expect(await controller.passUser({ name: 'asd' })).toEqual({ name: 'asd' });
252250
expect(await controller.passUser({})).toEqual({});
253251

254252
const date = new Date('1987-12-12T11:00:00.000Z');
255253

256-
expect(await controller.getPartialUser('asd', date)).toEqual({name: 'asd', date});
257-
expect(await controller.getPartialUser('asd')).toEqual({name: 'asd', date: undefined});
258-
expect(await controller.getPartialUser()).toEqual({name: undefined, date: undefined});
254+
expect(await controller.getPartialUser('asd', date)).toEqual({ name: 'asd', date });
255+
expect(await controller.getPartialUser('asd')).toEqual({ name: 'asd', date: undefined });
256+
expect(await controller.getPartialUser()).toEqual({ name: undefined, date: undefined });
259257

260258
const a = await controller.user({ name: 'peter2' });
261259
expect(a).toBe(true);
@@ -295,7 +293,7 @@ test('test observable', async () => {
295293
class TestController {
296294
@rpc.action()
297295
observer(): Observable<string> {
298-
return new Observable((observer) => {
296+
return new Observable(observer => {
299297
observer.next('a');
300298

301299
const timer = new ObserverTimer(observer);
@@ -316,7 +314,7 @@ test('test observable', async () => {
316314

317315
@rpc.action()
318316
user(name: string): Observable<User> {
319-
return new Observable((observer) => {
317+
return new Observable(observer => {
320318
observer.next(new User('first'));
321319

322320
const timer = new ObserverTimer(observer);
@@ -333,11 +331,11 @@ test('test observable', async () => {
333331

334332
const observable = await controller.observer();
335333

336-
await subscribeAndWait(observable.pipe(bufferCount(3)), async (next) => {
334+
await subscribeAndWait(observable.pipe(bufferCount(3)), async next => {
337335
expect(next).toEqual(['a', 'b', 'c']);
338336
});
339337

340-
await subscribeAndWait((await controller.user('pete')).pipe(bufferCount(2)), async (next) => {
338+
await subscribeAndWait((await controller.user('pete')).pipe(bufferCount(2)), async next => {
341339
expect(next[0]).toBeInstanceOf(User);
342340
expect(next[1]).toBeInstanceOf(User);
343341
expect(next[0].name).toEqual('first');

0 commit comments

Comments
 (0)