Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add type to test code #2702

Merged

Conversation

miettal
Copy link
Contributor

@miettal miettal commented Jul 5, 2024

$ npx tsc --strict
Found 3646 errors in 210 files.
↓
Found 1492 errors in 211 files.

Copy link

codecov bot commented Jul 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #2702      +/-   ##
=============================================
+ Coverage      56.03%   56.04%   +0.02%     
- Complexity      8041     8044       +3     
=============================================
  Files           2059     2059              
  Lines          87513    87511       -2     
  Branches        6418     6420       +2     
=============================================
+ Hits           49032    49041       +9     
+ Misses         36797    36786      -11     
  Partials        1684     1684              

@@ -37,7 +37,7 @@ describe('DateUtils', () => {
});

it('#isDateBefore - checks if given date is before date to be compared to', () => {
const date: Date = DateUtils.stringToDate('2023-01-01');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

input is gived by immediate value. so this code guarantee type is Date.

@@ -23,7 +23,7 @@ export namespace ArrayUtils {
* @param arr the arr
* @returns a number if arr not empty, else null
*/
export function findBiggestNumber(arr: number[]): number | null {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

test pattern has null and undefined. so this function work with null and undefined.

@@ -207,7 +207,7 @@ export namespace OeChartTester {
export type Data = {
type: 'data',
label: string | Converter,
value: number[] | null
Copy link
Contributor Author

Choose a reason for hiding this comment

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

test data inlucde null element.

@@ -37,7 +37,7 @@ describe('DateUtils', () => {
});

it('#isDateBefore - checks if given date is before date to be compared to', () => {
const date: Date = DateUtils.stringToDate('2023-01-01');
const date: Date = DateUtils.stringToDate('2023-01-01') as Date;
Copy link
Contributor

Choose a reason for hiding this comment

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

This works. lines below it also follows similar pattern. a slight modification like below can solve 5 other strict errors.
isDateBefore(date: Date, compareDate: Date) -> isDateBefore(date: Date | null, compareDate: Date | null).

But it's upto you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. thank you for your feedback. This time I want to focus just adding types, So I will keep this line. But I will memorize this information in mind.

@miettal miettal force-pushed the bugfix/fix-test-data-typing branch from 8414d12 to 24405e8 Compare August 1, 2024 01:22
@miettal
Copy link
Contributor Author

miettal commented Aug 1, 2024

rebased!

@sfeilmeier
Copy link
Contributor

sfeilmeier commented Aug 1, 2024

If I run:

npm audit fix && npm install && node_modules/.bin/ng lint --fix; node_modules/.bin/tsc && node_modules/.bin/tsc-strict && node_modules/.bin/ng build -c "openems,openems-backend-prod,prod"

I get

src/app/shared/utils/array/array.utils.ts(17,21): error TS2345: Argument of type 'number | null | undefined' is not assignable to parameter of type 'number'.
src/app/shared/utils/array/array.utils.ts(31,21): error TS2345: Argument of type 'number | null | undefined' is not assignable to parameter of type 'number'.

@miettal miettal force-pushed the bugfix/fix-test-data-typing branch from cb96c9f to fd22507 Compare August 1, 2024 16:46
@miettal miettal force-pushed the bugfix/fix-test-data-typing branch from fd22507 to e228a20 Compare August 1, 2024 16:47
@miettal
Copy link
Contributor Author

miettal commented Aug 1, 2024

Sorry, I mis-rebased. now its ok.

findSmallestNumber and findBiggestNumber was refactord.
e228a20

Copy link
Contributor

@sfeilmeier sfeilmeier left a comment

Choose a reason for hiding this comment

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

Thank you! 👍

@sfeilmeier sfeilmeier merged commit bb43bdf into OpenEMS:develop Aug 1, 2024
4 checks passed
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