Skip to content

Commit

Permalink
Merge pull request #170 from eliasmeire/jasmine-globals-create-spy-obj
Browse files Browse the repository at this point in the history
Add support for migrating jasmine.createSpyObj
  • Loading branch information
skovhus authored Jun 27, 2019
2 parents 8fff4e7 + 2241fa0 commit 157e880
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/transformers/jasmine-globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,5 +490,37 @@ export default function jasmineGlobals(fileInfo, api, options) {
});
});

root.find(j.CallExpression, {
callee: {
type: 'MemberExpression',
object: {
type: 'Identifier',
name: 'jasmine',
},
property: {
type: 'Identifier',
name: 'createSpyObj',
},
},
})
.filter(
path =>
path.node.arguments.length === 2 &&
path.node.arguments[1].type === 'ArrayExpression'
)
.forEach(path => {
const properties = path.node.arguments[1].elements.map(arg =>
j.objectProperty(
j.literal(arg.value),
j.callExpression(
j.memberExpression(j.identifier('jest'), j.identifier('fn')),
[]
)
)
);

j(path).replaceWith(j.objectExpression(properties));
});

return finale(fileInfo, j, root, options);
}
14 changes: 14 additions & 0 deletions src/transformers/jasmine-globals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,17 @@ testChanged(
expect.stringMatching('text');
`
);

testChanged(
'createSpyObj',
`
const spyObj = jasmine.createSpyObj('label', ['a', 'b', 'hyphen-ated']);
`,
`
const spyObj = {
'a': jest.fn(),
'b': jest.fn(),
'hyphen-ated': jest.fn()
};
`
);

0 comments on commit 157e880

Please sign in to comment.