Skip to content

Commit

Permalink
PR #2039 adjustments (#2046)
Browse files Browse the repository at this point in the history
* Added unit tests
* Updated CHANGELOG
  • Loading branch information
illiakovalenko authored Feb 25, 2025
1 parent 0c0ae9a commit 0898ba5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ Our versioning strategy is as follows:

## Unreleased

### 🎉 New Features & Improvements

* `[sitecore-jss-nextjs]` Link component supports prefetch property ([#2039](https://github.com/Sitecore/jss/pull/2039))([#2046](https://github.com/Sitecore/jss/pull/2046))

### 🐛 Bug Fixes

* `[templates/nextjs-sxa]`Fixed unsafe property access by replacing direct calls with optional chaining ([#2035](https://github.com/Sitecore/jss/pull/2035))
* `[templates/nextjs-sxa]` Fixed unsafe property access by replacing direct calls with optional chaining ([#2035](https://github.com/Sitecore/jss/pull/2035))

## 22.5.0

Expand Down
22 changes: 22 additions & 0 deletions packages/sitecore-jss-nextjs/src/components/Link.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,28 @@ describe('<Link />', () => {
expect(c.find(ReactLink).length).to.equal(0);
});

it('should render with prefetch prop provided', () => {
const field = {
href: '/lorem',
text: 'ipsum',
};
const c = mount(
<Page>
<Link field={field} prefetch={false} />
</Page>
);

const link = c.find('a');

expect(link.html()).to.contain(field.href);
expect(link.html()).to.contain(field.text);

expect(c.find(NextLink).length).to.equal(1);
expect(c.find(ReactLink).length).to.equal(0);

expect(c.find(NextLink).props().prefetch).to.equal(false);
});

it('should render other attributes with other props provided', () => {
const field = {
value: {
Expand Down
2 changes: 1 addition & 1 deletion packages/sitecore-jss-nextjs/src/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type LinkProps = ReactLinkProps & {
internalLinkMatcher?: RegExp;

/**
* Support next/link's prefetch prop.
* Next.js Link prefetch.
*/
prefetch?: NextLinkProps['prefetch'];
};
Expand Down

0 comments on commit 0898ba5

Please sign in to comment.