Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,17 @@ export function transformArrayWithExactContents(
return node;
}

const expectCall = node.expression.expression.expression;

// Splitting a negated assertion would assert that neither condition holds instead of not both.
if (ts.isPropertyAccessExpression(expectCall) && expectCall.name.text === 'not') {
const category = 'arrayWithExactContents-negated';
reporter.recordTodo(category, sourceFile, node);
addTodoComment(node, category);

return node;
}

if (!ts.isArrayLiteralExpression(argument.arguments[0])) {
const category = 'arrayWithExactContents-dynamic-variable';
reporter.recordTodo(category, sourceFile, node);
Expand All @@ -427,7 +438,6 @@ export function transformArrayWithExactContents(
'Transformed `jasmine.arrayWithExactContents()` to `.toHaveLength()` and `.toEqual(expect.arrayContaining())`.',
);

const expectCall = node.expression.expression.expression;
const arrayLiteral = argument.arguments[0];

const lengthCall = ts.factory.createCallExpression(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,16 @@ describe('transformArrayWithExactContents', () => {
expect(myArray).toEqual(jasmine.arrayWithExactContents(someOtherArray));
`,
},
{
description: 'should add a TODO for a negated toEqual(jasmine.arrayWithExactContents())',
input: `expect(myArray).not.toEqual(jasmine.arrayWithExactContents(['a', 'b']));`,
/* eslint-disable max-len */
expected: `
// TODO: vitest-migration: Cannot transform a negated jasmine.arrayWithExactContents. Splitting it would assert that neither condition holds instead of not both. Please migrate this manually.
expect(myArray).not.toEqual(jasmine.arrayWithExactContents(['a', 'b']));
`,
/* eslint-enable max-len */
},
];

testCases.forEach(({ description, input, expected }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ export const TODO_NOTES = {
message:
'Cannot transform jasmine.arrayWithExactContents with a dynamic variable. Please migrate this manually.',
},
'arrayWithExactContents-negated': {
message:
'Cannot transform a negated jasmine.arrayWithExactContents. ' +
'Splitting it would assert that neither condition holds instead of not both. ' +
'Please migrate this manually.',
},
'arrayWithExactContents-check': {
message:
"Verify this matches strict array content (multiset equality). Vitest's arrayContaining is a subset check.",
Expand Down
Loading