Repository: Yoctol/bottender
Pull request #314 (2018-07-20 05:17:06)

not print empty array other args in ConsoleBot fallbackMethods

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

[![Impacted file tree graph](https://codecov.io/gh/Yoctol/bottender/pull/314/graphs/tree.svg?width=650&height=150&src=pr&token=JX3EGtxYH3)](https://codecov.io/gh/Yoctol/bottender/pull/314?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master     #314   +/-   ##
=======================================
  Coverage   90.27%   90.27%           
=======================================
  Files         112      112           
  Lines        3301     3301           
  Branches      782      782           
=======================================
  Hits         2980     2980           
  Misses        281      281           
  Partials       40       40
```


| [Impacted Files](https://codecov.io/gh/Yoctol/bottender/pull/314?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/context/ConsoleContext.js](https://codecov.io/gh/Yoctol/bottender/pull/314/diff?src=pr&el=tree#diff-c3JjL2NvbnRleHQvQ29uc29sZUNvbnRleHQuanM=) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Yoctol/bottender/pull/314?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/Yoctol/bottender/pull/314?src=pr&el=footer). Last update [d371958...68b0654](https://codecov.io/gh/Yoctol/bottender/pull/314?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/context/ConsoleContext.js b/src/context/ConsoleContext.js
index 534ceb52..d86144cc 100644
--- a/src/context/ConsoleContext.js
+++ b/src/context/ConsoleContext.js
@@ -86,7 +86,7 @@ export default class ConsoleContext extends Context implements PlatformContext {
    */
   async sendText(text: string, ...args: Array<any>): Promise<void> {
     this._isHandled = true;
-    if (args && this._fallbackMethods) {
+    if (args.length > 0 && this._fallbackMethods) {
       this._client.sendText(
         `${text}\nwith other args:\n${JSON.stringify(args, null, 2)}`
       );


Test patch:
diff --git a/src/context/__tests__/ConsoleContext.spec.js b/src/context/__tests__/ConsoleContext.spec.js
index 532d78d9..5deb7d10 100644
--- a/src/context/__tests__/ConsoleContext.spec.js
+++ b/src/context/__tests__/ConsoleContext.spec.js
@@ -97,6 +97,17 @@ describe('#sendText', () => {
       `hello\nwith other args:\n${JSON.stringify([{ other: 1 }], null, 2)}`
     );
   });
+
+  it('should not print empty array other args', async () => {
+    const { context, client } = setup({ fallbackMethods: true });
+
+    await context.sendText('hello');
+
+    expect(client.sendText).not.toBeCalledWith(
+      `hello\nwith other args:\n${JSON.stringify([], null, 2)}`
+    );
+    expect(client.sendText).toBeCalledWith('hello');
+  });
 });
 
 describe('method missing', () => {