diff --git a/transforms/remove-onerror-sinon-stubs/__testfixtures__/convert-sandbox.input.js b/transforms/remove-onerror-sinon-stubs/__testfixtures__/convert-sandbox.input.js index e169107..1178ad8 100644 --- a/transforms/remove-onerror-sinon-stubs/__testfixtures__/convert-sandbox.input.js +++ b/transforms/remove-onerror-sinon-stubs/__testfixtures__/convert-sandbox.input.js @@ -5,6 +5,10 @@ test('foo test', async function (assert) { sandbox.stub(Ember, 'onerror', () => {}); sandbox.stub(Ember, 'onerror', fn); + sandbox.stub(Ember, 'foo', function() {}); + sandbox.stub(Ember, 'foo', () => {}); + sandbox.stub(Ember, 'foo', fn); + this.sandbox.stub(Ember, 'onerror', function() {}); this.sandbox.stub(Ember, 'onerror', () => {}); this.sandbox.stub(Ember, 'onerror', fn); diff --git a/transforms/remove-onerror-sinon-stubs/__testfixtures__/convert-sandbox.output.js b/transforms/remove-onerror-sinon-stubs/__testfixtures__/convert-sandbox.output.js index ce521b1..cdcffb1 100644 --- a/transforms/remove-onerror-sinon-stubs/__testfixtures__/convert-sandbox.output.js +++ b/transforms/remove-onerror-sinon-stubs/__testfixtures__/convert-sandbox.output.js @@ -5,6 +5,10 @@ test('foo test', async function (assert) { setupOnerror(() => {}); setupOnerror(fn); + sandbox.stub(Ember, 'foo', function() {}); + sandbox.stub(Ember, 'foo', () => {}); + sandbox.stub(Ember, 'foo', fn); + setupOnerror(function() {}); setupOnerror(() => {}); setupOnerror(fn); diff --git a/transforms/remove-onerror-sinon-stubs/__testfixtures__/convert-sinon.input.js b/transforms/remove-onerror-sinon-stubs/__testfixtures__/convert-sinon.input.js index bbd2f07..07152b6 100644 --- a/transforms/remove-onerror-sinon-stubs/__testfixtures__/convert-sinon.input.js +++ b/transforms/remove-onerror-sinon-stubs/__testfixtures__/convert-sinon.input.js @@ -5,6 +5,10 @@ test('foo test', async function (assert) { sinon.stub(Ember, 'onerror', () => {}); sinon.stub(Ember, 'onerror', fn); + sinon.stub(Ember, 'foo', function() {}); + sinon.stub(Ember, 'foo', () => {}); + sinon.stub(Ember, 'foo', fn); + this.sinon.stub(Ember, 'onerror', function() {}); this.sinon.stub(Ember, 'onerror', () => {}); this.sinon.stub(Ember, 'onerror', fn); diff --git a/transforms/remove-onerror-sinon-stubs/__testfixtures__/convert-sinon.output.js b/transforms/remove-onerror-sinon-stubs/__testfixtures__/convert-sinon.output.js index ce521b1..711623a 100644 --- a/transforms/remove-onerror-sinon-stubs/__testfixtures__/convert-sinon.output.js +++ b/transforms/remove-onerror-sinon-stubs/__testfixtures__/convert-sinon.output.js @@ -5,6 +5,10 @@ test('foo test', async function (assert) { setupOnerror(() => {}); setupOnerror(fn); + sinon.stub(Ember, 'foo', function() {}); + sinon.stub(Ember, 'foo', () => {}); + sinon.stub(Ember, 'foo', fn); + setupOnerror(function() {}); setupOnerror(() => {}); setupOnerror(fn); diff --git a/transforms/remove-onerror-sinon-stubs/index.js b/transforms/remove-onerror-sinon-stubs/index.js index 91326cf..010a33e 100644 --- a/transforms/remove-onerror-sinon-stubs/index.js +++ b/transforms/remove-onerror-sinon-stubs/index.js @@ -6,17 +6,31 @@ module.exports = function transformer(file, api) { const replacer = path => { let node = path.node; - let onErrorArg = node.arguments.pop(); + let emberArg = node.arguments[0]; + let onerrorArg = node.arguments[1]; + let onErrorFn = node.arguments[2]; - return j.callExpression(j.identifier('setupOnerror'), [onErrorArg]); + if (emberArg.name !== 'Ember' || onerrorArg.value !== 'onerror') { + return node; + } + + return j.callExpression(j.identifier('setupOnerror'), [onErrorFn]); } root.find(j.CallExpression, { + callee: { + type: 'MemberExpression', + property: { + type: 'Identifier', + name: 'stub' + } + }, arguments: { length: 3 } }) .replaceWith(replacer); + return root.toSource(); } \ No newline at end of file