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

[pact-js] Matches - extractPayload is failing to process null values #352

Closed
orekav opened this issue Jan 2, 2024 · 1 comment
Closed

Comments

@orekav
Copy link

orekav commented Jan 2, 2024

The typescript code looks as follow

// src/dsl/matchers.ts
// ...
// Recurse the object removing any underlying matching guff, returning
// the raw example content
export function extractPayload(value: AnyTemplate): AnyJson {
  if (isMatcher(value)) {
    return extractPayload(value.getValue());
  }

  if (Object.prototype.toString.call(value) === '[object Array]') {
    return (value as Array<AnyTemplate>).map(extractPayload);
  }

  if (value !== null && typeof value === 'object') {
    return Object.keys(value).reduce(
      (acc: JsonMap, propName: string) => ({
        ...acc,
        [propName]: extractPayload(
          (value as Record<string, AnyTemplate>)[propName]
        ),
      }),
      {}
    );
  }
  return value;
}

But the generated code is removing the null check
Screenshot 2024-01-02 at 14 56 03

@orekav
Copy link
Author

orekav commented Jan 2, 2024

The code belongs to 9.15.x not the 12.x.x
I am closing it

@orekav orekav closed this as completed Jan 2, 2024
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

No branches or pull requests

1 participant