diff --git a/src/transformers/jasmine-globals.test.ts b/src/transformers/jasmine-globals.test.ts index 3f76eb49..6570cef4 100644 --- a/src/transformers/jasmine-globals.test.ts +++ b/src/transformers/jasmine-globals.test.ts @@ -454,6 +454,19 @@ describe('types', () => { )) }) +test('arrayWithExactContents', () => { + expectTransformation( + ` + expect(array1).toEqual(jasmine.arrayWithExactContents(array2)); + expect([3,1,2]).toStrictEqual(jasmine.arrayWithExactContents([1,2,3])); + `, + ` + expect(array1.sort()).toEqual(array2.sort()); + expect([3,1,2].sort()).toStrictEqual([1,2,3].sort()); + ` + ) +}) + test('return value', () => { expectTransformation( ` diff --git a/src/transformers/jasmine-globals.ts b/src/transformers/jasmine-globals.ts index 51963906..6592d075 100644 --- a/src/transformers/jasmine-globals.ts +++ b/src/transformers/jasmine-globals.ts @@ -727,5 +727,62 @@ export default function jasmineGlobals(fileInfo, api, options) { } }) + root + .find(j.CallExpression, { + callee: { + type: 'MemberExpression', + object: { + type: 'CallExpression', + callee: { + type: 'Identifier', + name: 'expect', + }, + }, + property: { + type: 'Identifier', + name: (name) => name === 'toEqual' || name === 'toStrictEqual', + }, + }, + arguments: [ + { + type: 'CallExpression', + callee: { + type: 'MemberExpression', + object: { + type: 'Identifier', + name: 'jasmine', + }, + property: { + type: 'Identifier', + name: 'arrayWithExactContents', + }, + }, + }, + ], + }) + .replaceWith((path) => { + const expectArgument = path.value.callee.object.arguments[0] + const jasmineArgument = path.value.arguments[0].arguments[0] + const methodName = path.value.callee.property.name + + const newExpectArgument = j.callExpression( + j.memberExpression(expectArgument, j.identifier('sort')), + [] + ) + + const newJasmineArgument = j.callExpression( + j.memberExpression(jasmineArgument, j.identifier('sort')), + [] + ) + + return j.callExpression( + j.memberExpression( + j.callExpression(j.identifier('expect'), [newExpectArgument]), + j.identifier(methodName) + ), + [newJasmineArgument] + ) + }) + return finale(fileInfo, j, root, options) }