Repository: neet/masto.js
Pull request #92 (2019-06-29 16:03:09)

Fix filters changed signature

codecov-io: # [Codecov](https://codecov.io/gh/neet/masto.js/pull/92?src=pr&el=h1) Report
> Merging [#92](https://codecov.io/gh/neet/masto.js/pull/92?src=pr&el=desc) into [master](https://codecov.io/gh/neet/masto.js/commit/6575d4a5eb49a0e96681e54c89c7c6a7bbe5740b?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/neet/masto.js/pull/92/graphs/tree.svg?width=650&token=SW9FhwMnZ3&height=150&src=pr)](https://codecov.io/gh/neet/masto.js/pull/92?src=pr&el=tree)

```diff
@@          Coverage Diff          @@
##           master    #92   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          10     10           
  Lines         420    419    -1     
  Branches       44     39    -5     
=====================================
- Hits          420    419    -1
```


| [Impacted Files](https://codecov.io/gh/neet/masto.js/pull/92?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/gateway/websocket.ts](https://codecov.io/gh/neet/masto.js/pull/92/diff?src=pr&el=tree#diff-c3JjL2dhdGV3YXkvd2Vic29ja2V0LnRz) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/neet/masto.js/pull/92?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/neet/masto.js/pull/92?src=pr&el=footer). Last update [6575d4a...e04fb28](https://codecov.io/gh/neet/masto.js/pull/92?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/gateway/websocket.ts b/src/gateway/websocket.ts
index 9a083cc6..dbdda6df 100644
--- a/src/gateway/websocket.ts
+++ b/src/gateway/websocket.ts
@@ -1,4 +1,3 @@
-// tslint:disable no-unnecessary-override
 import EventEmitter from 'eventemitter3';
 import WebSocket from 'isomorphic-ws';
 import { Conversation } from '../entities/conversation';
@@ -14,7 +13,7 @@ export interface EventTypeMap {
   /** User's notification */
   notification: [Notification];
   /** User's filter changed */
-  filters_changed: [undefined];
+  filters_changed: [];
   /** Status added to a conversation */
   conversation: [Conversation];
 }
@@ -43,13 +42,8 @@ export class WebSocketEvents extends EventEmitter<EventTypeMap> {
   public connect(url: string, protocols?: string | string[]) {
     return new Promise<WebSocketEvents>((resolve, reject) => {
       this.ws = new WebSocket(url, protocols);
-
-      this.ws.addEventListener('open', () => {
-        resolve(this);
-      });
-
+      this.ws.addEventListener('open', () => resolve(this));
       this.ws.addEventListener('message', this.handleMessage);
-
       this.ws.addEventListener('error', reject);
     });
   }
@@ -73,7 +67,7 @@ export class WebSocketEvents extends EventEmitter<EventTypeMap> {
     try {
       args = [JSON.parse(event.payload)];
     } catch {
-      args = [undefined];
+      args = [];
     }
 
     this.emit(event.event, ...args);


Test patch:
diff --git a/src/gateway/__tests__/websocket.spec.ts b/src/gateway/__tests__/websocket.spec.ts
index ed48a21b..9f76c396 100644
--- a/src/gateway/__tests__/websocket.spec.ts
+++ b/src/gateway/__tests__/websocket.spec.ts
@@ -89,7 +89,7 @@ describe('WebSocketEvents', () => {
     expect(mockEmit).toBeCalledWith('update', originalPayload);
   });
 
-  test('emit event with undefined when parsing fail', () => {
+  test('emit event without callback when parsing failed', () => {
     const originalPayload = 'foobar';
     const originalData = {
       event: 'update',
@@ -97,13 +97,6 @@ describe('WebSocketEvents', () => {
     };
 
     wsEvents.handleMessage({ data: JSON.stringify(originalData) });
-    expect(mockEmit).toBeCalledWith('update', undefined);
-  });
-
-  test('subscribe events via event emitter', async () => {
-    const cb = jest.fn();
-    const stream = await wsEvents.on('update', cb);
-    expect(mockOn).toBeCalledWith('update', cb);
-    expect(stream).toBeUndefined(); // mock
+    expect(mockEmit).toBeCalledWith('update');
   });
 });