Repository: skovhus/jest-codemods
Pull request #158 (2019-03-29 17:35:02)

jasmine-globals: Support *.calls.argsFor(index)
Supports `*.calls.argsFor(index)`

https://jasmine.github.io/2.9/introduction#section-33

Replaces it with `*.mock.calls[index]`, the same approach currently used by the `*. argsForCall` logic

Jest calls docs: https://jestjs.io/docs/en/mock-function-api#mockfnmockcalls

skovhus: @JHilker thanks for contributing! Can I get you to resolve the branch conflict? Thanks for splitting this up into 3 PRs, makes reviewing much easier. 👍👍 

Patch:
diff --git a/src/transformers/jasmine-globals.js b/src/transformers/jasmine-globals.js
index 7a14a4c..d9c8a59 100644
--- a/src/transformers/jasmine-globals.js
+++ b/src/transformers/jasmine-globals.js
@@ -327,6 +327,36 @@ export default function jasmineGlobals(fileInfo, api, options) {
             );
         });
 
+    root
+        // find `*.calls.argsFor(index)`
+        .find(j.CallExpression, {
+            callee: {
+                type: 'MemberExpression',
+                object: {
+                    type: 'MemberExpression',
+                    property: {
+                        type: 'Identifier',
+                        name: 'calls',
+                    },
+                },
+                property: {
+                    type: 'Identifier',
+                    name: 'argsFor',
+                },
+            },
+        })
+        .forEach(path => {
+            const expressionMockCalls = j.memberExpression(
+                j.memberExpression(path.node.callee.object.object, j.identifier('mock')),
+                j.identifier('calls')
+            );
+
+            // make it `*.mock.calls[index]`
+            j(path).replaceWith(
+                j.memberExpression(expressionMockCalls, path.node.arguments[0])
+            );
+        });
+
     root
         // replace `andCallFake` with `mockImplementation`
         .find(j.MemberExpression, {


Test patch:
diff --git a/src/transformers/jasmine-globals.test.js b/src/transformers/jasmine-globals.test.js
index e11b53b..c8c377d 100644
--- a/src/transformers/jasmine-globals.test.js
+++ b/src/transformers/jasmine-globals.test.js
@@ -80,8 +80,6 @@ testChanged(
     getMock(stuff).calls.count() > 1;
     wyoming.cheyenne.callCount
     args.map()
-    oklahoma.argsForCall[0]
-    idaho.argsForCall[0][1]
     spyOn('stuff').andCallFake(fn);
     hmm.andCallFake(fn);
     spyOn('stuff').andReturn('lol');
@@ -95,8 +93,6 @@ testChanged(
     getMock(stuff).mock.calls.length > 1;
     wyoming.cheyenne.mock.calls.length
     args.map()
-    oklahoma.mock.calls[0]
-    idaho.mock.calls[0][1]
     jest.spyOn('stuff').mockImplementation(fn);
     hmm.mockImplementation(fn);
     jest.spyOn('stuff').mockReturnValue('lol');
@@ -133,6 +129,30 @@ testChanged(
     `
 );
 
+testChanged(
+    '*.argsForCall',
+    `
+    oklahoma.argsForCall[0]
+    idaho.argsForCall[0][1]
+    `,
+    `
+    oklahoma.mock.calls[0]
+    idaho.mock.calls[0][1]
+    `
+);
+
+testChanged(
+    '*.calls.argsFor()',
+    `
+    oklahoma.calls.argsFor(0)
+    idaho.calls.argsFor(0)[1]
+    `,
+    `
+    oklahoma.mock.calls[0]
+    idaho.mock.calls[0][1]
+    `
+);
+
 testChanged(
     'jasmine.clock()',
     `