Skip to content

Commit

Permalink
feat(jasmine): add support for spyOnProperty (#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
jase88 authored Aug 29, 2024
1 parent 11ce2fe commit 4e05b49
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/transformers/jasmine-globals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ test('spyOn', () => {
)
})

test('spyOnProperty', () => {
expectTransformation(
`
spyOnProperty(component, 'propertyName1').and.returnValue(42);
spyOnProperty(component, 'propertyName2', 'get').and.returnValue(true);
jest.spyOn(something, 'property', 'get');`,
`
jest.spyOn(component, 'propertyName1', 'get').mockReturnValue(42);
jest.spyOn(component, 'propertyName2', 'get').mockReturnValue(true);
jest.spyOn(something, 'property', 'get');`
)
})

test('jasmine.createSpy', () => {
expectTransformation(
`
Expand Down
13 changes: 13 additions & 0 deletions src/transformers/jasmine-globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,19 @@ export default function jasmineGlobals(fileInfo, api, options) {
path.node.callee = j.memberExpression(j.identifier('jest'), j.identifier('spyOn'))
})

root
.find(j.CallExpression, {
callee: { type: 'Identifier', name: 'spyOnProperty' },
})
.forEach((path) => {
path.node.callee = j.memberExpression(j.identifier('jest'), j.identifier('spyOn'))

// explicitly add third parameter, which is defaulted as 'get' in jasmine
if (path.node.arguments.length === 2) {
path.node.arguments.push(j.literal('get'))
}
})

root
.find(j.CallExpression, {
// find all `*.calls.count()`
Expand Down

0 comments on commit 4e05b49

Please sign in to comment.