Skip to content

Commit b2931dc

Browse files
Throw error on unsupported broadcaster (#396)
* Throw error on unsupported broadcaster * update CS * fix CS * fix cs * fix eslint * Removed return * fix CS * Update echo.ts * Update echo.test.ts --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 786f814 commit b2931dc

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/echo.ts

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export default class Echo {
4848
this.connector = new NullConnector(this.options);
4949
} else if (typeof this.options.broadcaster == 'function') {
5050
this.connector = new this.options.broadcaster(this.options);
51+
} else {
52+
throw new Error(
53+
`Broadcaster ${typeof this.options.broadcaster} ${this.options.broadcaster} is not supported.`
54+
);
5155
}
5256
}
5357

tests/echo.test.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Echo from '../src/echo';
2+
3+
describe('Echo', () => {
4+
test('it will not throw error for supported driver', () => {
5+
expect(() => new Echo({ broadcaster: 'reverb' })).not.toThrowError(
6+
'Broadcaster string reverb is not supported.'
7+
);
8+
9+
expect(() => new Echo({ broadcaster: 'pusher' })).not.toThrowError(
10+
'Broadcaster string pusher is not supported.'
11+
);
12+
13+
expect(() => new Echo({ broadcaster: 'socket.io' })).not.toThrowError(
14+
'Broadcaster string socket.io is not supported.'
15+
);
16+
17+
expect(() => new Echo({ broadcaster: 'null' })).not.toThrowError('Broadcaster string null is not supported.');
18+
19+
// eslint-disable-next-line @typescript-eslint/no-empty-function
20+
expect(() => new Echo({ broadcaster: () => {} })).not.toThrowError('Broadcaster function is not supported.');
21+
});
22+
23+
test('it will throw error for unsupported driver', () => {
24+
expect(() => new Echo({ broadcaster: 'foo' })).toThrowError('Broadcaster string foo is not supported.');
25+
});
26+
});

0 commit comments

Comments
 (0)