|
1 | 1 | /** @jest-environment jsdom */ |
2 | 2 |
|
| 3 | +import { renderClient } from '../../jest/browser-utils'; |
3 | 4 | import { Helmet } from '../../src'; |
4 | 5 | import { HELMET_ATTRIBUTE } from '../../src/constants'; |
5 | | -import { renderClient } from '../../jest/browser-utils'; |
6 | 6 |
|
7 | 7 | describe('base tag', () => { |
8 | 8 | describe('API', () => { |
@@ -30,8 +30,21 @@ describe('base tag', () => { |
30 | 30 | expect(existingTags).toHaveLength(0); |
31 | 31 | }); |
32 | 32 |
|
33 | | - it('tags without \'href\' are not accepted', () => { |
34 | | - renderClient(<Helmet base={{ property: 'won\'t work' }} />); |
| 33 | + it("tags with only 'target' are accepted", () => { |
| 34 | + renderClient(<Helmet base={{ target: '_blank' }} />); |
| 35 | + const existingTags = [...document.head.querySelectorAll(`base[${HELMET_ATTRIBUTE}]`)]; |
| 36 | + |
| 37 | + expect(existingTags).toBeDefined(); |
| 38 | + expect(existingTags).toHaveLength(1); |
| 39 | + const firstTag = existingTags[0]!; |
| 40 | + expect(firstTag).toBeInstanceOf(Element); |
| 41 | + expect(firstTag.getAttribute).toBeDefined(); |
| 42 | + expect(firstTag).toHaveAttribute('target', '_blank'); |
| 43 | + expect(firstTag).not.toHaveAttribute('href'); |
| 44 | + }); |
| 45 | + |
| 46 | + it("tags without 'href' or 'target' are not accepted", () => { |
| 47 | + renderClient(<Helmet base={{ property: "won't work" }} />); |
35 | 48 | const existingTags = document.head.querySelectorAll(`base[${HELMET_ATTRIBUTE}]`); |
36 | 49 |
|
37 | 50 | expect(existingTags).toBeDefined(); |
@@ -97,7 +110,25 @@ describe('base tag', () => { |
97 | 110 | expect(existingTags).toHaveLength(0); |
98 | 111 | }); |
99 | 112 |
|
100 | | - it('tags without \'href\' are not accepted', () => { |
| 113 | + it("tags with only 'target' are accepted", () => { |
| 114 | + renderClient( |
| 115 | + <Helmet> |
| 116 | + <base target="_blank" /> |
| 117 | + </Helmet>, |
| 118 | + ); |
| 119 | + |
| 120 | + const existingTags = [...document.head.querySelectorAll(`base[${HELMET_ATTRIBUTE}]`)]; |
| 121 | + |
| 122 | + expect(existingTags).toBeDefined(); |
| 123 | + expect(existingTags).toHaveLength(1); |
| 124 | + const firstTag = existingTags[0]!; |
| 125 | + expect(firstTag).toBeInstanceOf(Element); |
| 126 | + expect(firstTag.getAttribute).toBeDefined(); |
| 127 | + expect(firstTag).toHaveAttribute('target', '_blank'); |
| 128 | + expect(firstTag).not.toHaveAttribute('href'); |
| 129 | + }); |
| 130 | + |
| 131 | + it("tags without 'href' or 'target' are not accepted", () => { |
101 | 132 | /* eslint-disable react/no-unknown-property */ |
102 | 133 | renderClient( |
103 | 134 | <Helmet> |
|
0 commit comments