I have a method that check and replaces with empty strings those deltas in which the insert is a string and in which the length is zero when trimmed.
trimDelta(ops = []): void {
for (const delta of ops) {
if (
typeof delta?.insert === 'string' &&
delta?.insert?.trim().length === 0
) {
delta.insert = '';
} else {
break;
}
}
}
I have to check if when there is no string, when the string does not stretch to zero length, when there are only empty strings, etc. How to implement this case?
CodePudding user response:
Every test follows 3 basic steps:
- Setup teststate
- Execute
- Verify
Step 1 is very simple in your case, you define an ops object array. Step 2 is executing trimDelta function with the array from step 1. You save the result in another object array. In Step 3 you check the result and compare it's values. How would you expect the 2nd array to have been altered?