Repository: skovhus/jest-codemods
Pull request #364 (2022-08-22 04:01:15)

[sinon] Implement `stub.resetBehavior()` and `stub.resetHistory()`
ref: https://sinonjs.org/releases/latest/stubs/

>stub.reset();
Resets both behaviour and history of the stub.
This is equivalent to calling both stub.resetBehavior() and stub.resetHistory()

codecov[bot]: # [Codecov](https://codecov.io/gh/skovhus/jest-codemods/pull/364?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kenneth+Skovhus) Report
> Merging [#364](https://codecov.io/gh/skovhus/jest-codemods/pull/364?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kenneth+Skovhus) (8e98b9e) into [main](https://codecov.io/gh/skovhus/jest-codemods/commit/bd56756fc6d2a57b533f9271d7d657ce82890c2d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kenneth+Skovhus) (bd56756) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##             main     #364   +/-   ##
=======================================
  Coverage   92.19%   92.19%           
=======================================
  Files          26       26           
  Lines        1896     1896           
  Branches      398      398           
=======================================
  Hits         1748     1748           
  Misses        102      102           
  Partials       46       46           
```


| [Impacted Files](https://codecov.io/gh/skovhus/jest-codemods/pull/364?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kenneth+Skovhus) | Coverage Δ | |
|---|---|---|
| [src/transformers/sinon.ts](https://codecov.io/gh/skovhus/jest-codemods/pull/364/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kenneth+Skovhus#diff-c3JjL3RyYW5zZm9ybWVycy9zaW5vbi50cw==) | `88.75% <ø> (ø)` | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kenneth+Skovhus). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kenneth+Skovhus)


Patch:
diff --git a/src/transformers/sinon.ts b/src/transformers/sinon.ts
index 67929fe..fccb71e 100644
--- a/src/transformers/sinon.ts
+++ b/src/transformers/sinon.ts
@@ -35,6 +35,8 @@ const SINON_CALLED_WITH_METHODS = ['calledWith', 'notCalledWith']
 const SINON_SPY_METHODS = ['spy', 'stub']
 const SINON_MOCK_RESETS = {
   reset: 'mockReset',
+  resetBehavior: 'mockReset',
+  resetHistory: 'mockReset',
   restore: 'mockRestore',
 }
 const SINON_MATCHERS = {


Test patch:
diff --git a/src/transformers/sinon.test.ts b/src/transformers/sinon.test.ts
index 5b778d9..5fddb52 100644
--- a/src/transformers/sinon.test.ts
+++ b/src/transformers/sinon.test.ts
@@ -379,12 +379,16 @@ describe('mocks', () => {
         Api.get.restore()
         Api.get.reset()
         sinon.restore()
+        stub.resetBehavior()
+        stub.resetHistory()
 `,
       `
         stub.mockRestore()
         Api.get.mockRestore()
         Api.get.mockReset()
         jest.restoreAllMocks()
+        stub.mockReset()
+        stub.mockReset()
 `
     )
   })