Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
bienzaaron authored May 16, 2024
2 parents 0d2e049 + 5199f2e commit 5c61850
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/transformers/jasmine-globals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ test('spyOn', () => {
jest.spyOn();
spyOn(stuff);
jest.spyOn().mockImplementation();
jest.spyOn(stuff).and.resolveTo('lmao');
jest.spyOn(stuff).and.rejectWith('oh no');
const fetchSpy = spyOn(window, 'fetch').and.resolveTo({json: {}});
`,
`
jest.spyOn().mockReturnValue();
Expand All @@ -36,6 +39,9 @@ test('spyOn', () => {
jest.spyOn();
jest.spyOn(stuff).mockImplementation(() => {});
jest.spyOn().mockImplementation();
jest.spyOn(stuff).mockResolvedValue('lmao');
jest.spyOn(stuff).mockRejectedValue('oh no');
const fetchSpy = jest.spyOn(window, 'fetch').mockResolvedValue({json: {}});
`
)
})
Expand All @@ -49,6 +55,9 @@ test('jasmine.createSpy', () => {
jasmine.createSpy().and.callFake(arg => arg);
jasmine.createSpy().and.returnValue('lmao');
const spy2 = jasmine.createSpy().and.returnValue('lmao');
jasmine.createSpy().and.resolveTo('lmao');
jasmine.createSpy().and.rejectWith('oh no');
const spy3 = jasmine.createSpy().and.resolveTo('lmao');
`,
`
jest.fn();
Expand All @@ -57,8 +66,14 @@ test('jasmine.createSpy', () => {
jest.fn(arg => arg);
jest.fn(() => 'lmao');
const spy2 = jest.fn(() => 'lmao');
jest.fn().mockResolvedValue('lmao');
jest.fn().mockRejectedValue('oh no');
const spy3 = jest.fn().mockResolvedValue('lmao');
`
)

// Ensure we haven't missed any console warnings
expect(consoleWarnings).toEqual([])
})

test('not supported jasmine.createSpy().and.*', () => {
Expand Down
24 changes: 24 additions & 0 deletions src/transformers/jasmine-globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ export default function jasmineGlobals(fileInfo, api, options) {
path.node.arguments = [j.arrowFunctionExpression([], path.node.arguments[0])]
break
}
// This is transformed by the *.and.*() expression handling below
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 @@ -137,6 +145,8 @@ export default function jasmineGlobals(fileInfo, api, options) {
// - `existingSpy.and.callFake(..)`
// - `spyOn().and.returnValue(..)`
// - `existingSpy.and.returnValue(..)`
// - `spyOn().and.resolveTo(..)`
// - `existingSpy.and.rejectWith(..)`
callee: {
type: 'MemberExpression',
object: {
Expand Down Expand Up @@ -171,6 +181,20 @@ export default function jasmineGlobals(fileInfo, api, options) {
path.node.callee.property.name = 'mockReturnValue'
break
}
// `*.and.resolveTo()` is equivalent of jest
// `*.mockResolvedValue()`
case 'resolveTo': {
path.node.callee.object = path.node.callee.object.object
path.node.callee.property.name = 'mockResolvedValue'
break
}
// `*.and.rejectWith()` is equivalent of jest
// `*.mockRejectedValue()`
case 'rejectWith': {
path.node.callee.object = path.node.callee.object.object
path.node.callee.property.name = 'mockRejectedValue'
break
}
}
})

Expand Down

0 comments on commit 5c61850

Please sign in to comment.