Skip to content

test(core): rework built-in repeter track fn tests#51903

Closed
pkozlowski-opensource wants to merge 1 commit intoangular:mainfrom
pkozlowski-opensource:control_flow_track_tests
Closed

test(core): rework built-in repeter track fn tests#51903
pkozlowski-opensource wants to merge 1 commit intoangular:mainfrom
pkozlowski-opensource:control_flow_track_tests

Conversation

@pkozlowski-opensource
Copy link
Copy Markdown
Member

Rework existing tests so those do NOT depend on the number of calls to the tracking function.

Rework existing tests so those do NOT depend on the number of
calls to the tracking function.
@pkozlowski-opensource pkozlowski-opensource added action: review The PR is still awaiting reviews from at least one requested reviewer area: core Issues related to the framework runtime labels Sep 26, 2023
@ngbot ngbot Bot added this to the Backlog milestone Sep 26, 2023
Comment on lines +374 to +375
trackingFn(index: number, items: string[]) {
return items[index];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about extending this a bit with

Suggested change
trackingFn(index: number, items: string[]) {
return items[index];
trackingFn(index: number, items: string[]) {
trackByCalled = true;
expect(typeof index).toBe('number');
expect(items).toBe(this.items);
return items[index];

and then verifying that trackByCalled is indeed true after rendering, as the current tests would also work if the tracking function is never invoked at all.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or perhaps better yet would be to maintain a Map<number, string[]> to track all indices and their items value, which should end up containing three items.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have an alternative (but also deduping approach in #51980)


const fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();
expect(calls).toEqual([
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I was trying to capture with these tests was that the correct value is passed into the function since we have some special logic around how we generate the function. I don't think that the new tests capture that behavior anymore.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have an alternative approach in #51980.

WDYT?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think those are fine.

@pkozlowski-opensource
Copy link
Copy Markdown
Member Author

Will be tackled as part of #51980

@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Nov 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: core Issues related to the framework runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants