Skip to content

Commit

Permalink
fix(jasmine): .and.stub() usage is correctly replaced
Browse files Browse the repository at this point in the history
  • Loading branch information
jase88 committed Sep 15, 2024
1 parent 17ca751 commit 4a829df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/transformers/jasmine-globals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ test('spyOn', () => {
jest.spyOn(stuff).and.rejectWith('oh no');
const fetchSpy = spyOn(window, 'fetch').and.resolveTo({json: {}});
existingSpy.and.callThrough();
spyOn(something, 'foo').and.stub().and.returnValue(42);
mySpy.and.stub();
`,
`
jest.spyOn().mockReturnValue();
Expand All @@ -97,6 +99,8 @@ test('spyOn', () => {
jest.spyOn(stuff).mockRejectedValue('oh no');
const fetchSpy = jest.spyOn(window, 'fetch').mockResolvedValue({json: {}});
existingSpy.mockRestore();
jest.spyOn(something, 'foo').mockReturnValue(42);
mySpy.mockImplementation(() => {});
`
)
})
Expand Down
16 changes: 12 additions & 4 deletions src/transformers/jasmine-globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,10 @@ export default function jasmineGlobals(fileInfo, api, options) {
break
}
// This is transformed by the *.and.*() expression handling below
case 'rejectWith':
case 'resolveTo': {
break
}
// This is transformed by the *.and.*() expression handling below
case 'rejectWith': {
break
}
default: {
logWarning(
`Unsupported Jasmine functionality "jasmine.createSpy().and.${spyType}".`,
Expand Down Expand Up @@ -362,6 +359,17 @@ export default function jasmineGlobals(fileInfo, api, options) {
]
break
}

case 'stub': {
if (path.parentPath.node.type === 'MemberExpression') {
j(path).replaceWith(path.node.callee.object.object)
} else {
path.node.callee.object = path.node.callee.object.object
path.node.callee.property.name = 'mockImplementation'
path.node.arguments = [emptyArrowFn]
}
break
}
}
})

Expand Down

0 comments on commit 4a829df

Please sign in to comment.