Read only
    export default function transformer(file, { jscodeshift: j }, options) {
      const source = j(file.source);
    
      const matcherMap = {
        toBeCalled: 'toHaveBeenCalled',
        toBeCalledTimes: 'toHaveBeenCalledTimes',
        toBeCalledWith: 'toHaveBeenCalledWith',
        lastCalledWith: 'toHaveBeenLastCalledWith',
        nthCalledWith: 'toHaveBeenNthCalledWith',
        toReturn: 'toHaveReturned',
        toReturnTimes: 'toHaveReturnedTimes',
        toReturnWith: 'toHaveReturnedWith',
        lastReturnedWith: 'toHaveLastReturnedWith',
        nthReturnedWith: 'toHaveNthReturnedWith',
        toThrowError: 'toThrow'
      };
    
      source.find(j.CallExpression, {
        callee: {
          object: {
            callee: {
              name: 'expect'
            }
          },
          property: {
            name: name => Object.keys(matcherMap).includes(name)
          }
        }
      }).forEach(path => {
        const oldName = path.node.callee.property.name;
        path.node.callee.property.name = matcherMap[oldName];
      });
    
      return source.toSource(options.printOptions);
    }
    Input
    expect(fn).toBeCalled();
    expect(fn).toBeCalledTimes(2);
    expect(fn).toBeCalledWith(arg);
    expect(fn).lastCalledWith(arg);
    expect(fn).nthCalledWith(1, arg);
    expect(fn).toReturn();
    expect(fn).toReturnTimes(2);
    expect(fn).toReturnWith(val);
    expect(fn).lastReturnedWith(val);
    expect(fn).nthReturnedWith(1, val);
    expect(func).toThrowError(message);
    Output
    loading
    Read-only
    Open on CodeSandboxOpen Sandbox