Skip to content

Conversation

@sjin9
Copy link

@sjin9 sjin9 commented Nov 9, 2023

No description provided.

<!-- <app-counter *ngFor="let counter of counters, index as i" [number]="counter.num" (change)="counter.num = $event">
</app-counter>
<button (click)="removeCounter(i)" >Remove</button> -->
<div class="counter-format" *ngFor="let counter of counters; let i = index">

Choose a reason for hiding this comment

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

Good: remove counter from group instead of passing the id to counter! 👍

@celianiu
Copy link

Good:

  1. sufficient test cases;
  2. Baby step commits;

@@ -0,0 +1,11 @@
<button (click)="onAdd()">Add counter</button>
<!-- <app-counter *ngFor="let counter of counters, index as i" [number]="counter.num" (change)="counter.num = $event">

Choose a reason for hiding this comment

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

suggestion: remove dead code

const incrementValue=3
component.counters[0].num += incrementValue

expect(component.sum).toEqual(initialSum+incrementValue)

Choose a reason for hiding this comment

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

suggestion: initialSum+incrementValue can be extracted as a const named expected

it('should reset numbers in counters to 0 when call resetSum', () => {
component.reset()
const resetSum = component.sum
expect(resetSum).toBe(0)

Choose a reason for hiding this comment

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

suggestion: no need to verify Sum here, since we already cover the logic in another test

const resetSum = component.sum
expect(resetSum).toBe(0)

component.counters.forEach(counter => {

Choose a reason for hiding this comment

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

well: nice to verify counters when test reset.

})

it('should reset numbers in counters to 0 when call resetSum', () => {
component.reset()

Choose a reason for hiding this comment

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

suggestion: we also need give init data for counters, to see the value change, like
components.counters = {
{num: 1},
{num: 2}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants