Skip to content
This repository has been archived by the owner on May 29, 2023. It is now read-only.

feat: provide typesafe mocks for SSR_USER_AGENT & SSR_LOCATION #41

Merged
merged 2 commits into from
Dec 14, 2022
Merged

feat: provide typesafe mocks for SSR_USER_AGENT & SSR_LOCATION #41

merged 2 commits into from
Dec 14, 2022

Conversation

nsbarsukov
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows Conventional Commits
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Refactoring (no functional changes, no api changes)
  • Other... Please describe:

What is the current behavior?

SSR_USER_AGENT and SSR_LOCATION tokens dont have mock-fallbacks.
But they are required for prerender-strategy.

What is the new behavior?

Closes #36

Does this PR introduce a breaking change?

  • Yes
  • No

@@ -58,6 +58,8 @@ from requests. Use the following helpers to harvest that info:
**server.ts:**

```typescript
import {provideLocation, provideUserAgent} from '@ng-web-apis/universal';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

export const SSR_LOCATION = new InjectionToken<Location>(
'Location object passed from server side',
{factory: () => new LocationMock()},
Copy link
Member

Choose a reason for hiding this comment

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

You cannot use factory in this token, unfortunately. It takes precedence over providing it because of some weird Injector hierarchy in case of SSR, I couldn't figure it out completely. Instead make them optional and provide fallback here:
https://github.com/ng-web-apis/universal/blob/master/projects/universal/src/constants/universal-user-agent.ts
https://github.com/ng-web-apis/universal/blob/master/projects/universal/src/constants/universal-location.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@waterplea waterplea left a comment

Choose a reason for hiding this comment

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

Can you do something about the coverage?

@nsbarsukov
Copy link
Contributor Author

Can you do something about the coverage?

If I've not mistaken It is already 100%:
Screenshot 2022-12-06 at 14 17 53

@waterplea waterplea merged commit ee98d1b into ng-web-apis:master Dec 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tip to README on how to import provideLocation & provideUserAgent
2 participants