Skip to content

Commit 1dfe7fd

Browse files
committed
fix: upgrade intl-messageformat and tests
1 parent 6b6477a commit 1dfe7fd

File tree

4 files changed

+73
-53
lines changed

4 files changed

+73
-53
lines changed

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"hoist-non-react-statics": "^3.3.0",
4444
"intl-format-cache": "^4.1.2",
4545
"intl-locales-supported": "^1.4.2",
46-
"intl-messageformat": "^5.3.0",
46+
"intl-messageformat": "^5.4.2",
4747
"intl-messageformat-parser": "^2.1.3",
4848
"invariant": "^2.1.1",
4949
"react": "^16.3.0",

test/unit/components/html-message.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,6 @@ describe('<FormattedHTMLMessage>', () => {
121121
intl
122122
).html();
123123

124-
expect(renderedHtml).toBe('<span>Hello, <b>[object Object]</b>!</span>');
124+
expect(renderedHtml).not.toBe('<span>Hello, <b><i>Eric</i></b>!</span>');
125125
});
126126
});

test/unit/components/message.tsx

+68-48
Original file line numberDiff line numberDiff line change
@@ -111,58 +111,78 @@ describe('<FormattedMessage>', () => {
111111
expect(rendered.text()).toBe('Jest');
112112
});
113113

114-
it('supports rich-text message formatting', () => {
115-
const rendered = mountWithProvider(
116-
{
117-
id: 'hello',
118-
defaultMessage: 'Hello, <b>{name}</b>!',
119-
values: {
120-
name: 'Jest',
121-
b: (name: string) => <b>{name}</b>,
114+
describe('rich text', function () {
115+
it('supports legacy behavior', () => {
116+
const rendered = mountWithProvider(
117+
{
118+
id: 'hello',
119+
defaultMessage: 'Hello, {name}!',
120+
values: {
121+
name: <b>Jest</b>,
122+
},
122123
},
123-
},
124-
intl
125-
);
126-
127-
const nameNode = rendered.find('b');
128-
expect(nameNode.type()).toBe('b');
129-
expect(nameNode.text()).toBe('Jest');
130-
});
131-
132-
it('supports rich-text message formatting w/ self-closing tag', () => {
133-
const rendered = mountWithProvider(
134-
{
135-
id: 'hello',
136-
defaultMessage: 'Hello, <name/>',
137-
values: {
138-
name: <b>Jest</b>,
124+
intl
125+
);
126+
127+
const nameNode = rendered.find('b');
128+
expect(nameNode.type()).toBe('b');
129+
expect(nameNode.text()).toBe('Jest');
130+
});
131+
it('supports rich-text message formatting', () => {
132+
const rendered = mountWithProvider(
133+
{
134+
id: 'hello',
135+
defaultMessage: 'Hello, <b>{name}</b>!',
136+
values: {
137+
name: 'Jest',
138+
b: (name: string) => <b>{name}</b>,
139+
},
139140
},
140-
},
141-
intl
142-
);
143-
144-
const nameNode = rendered.find('b');
145-
expect(nameNode.type()).toBe('b');
146-
expect(nameNode.text()).toBe('Jest');
147-
});
148-
149-
it('supports rich-text message formatting in function-as-child pattern', () => {
150-
const rendered = mountWithProvider(
151-
{
152-
id: 'hello',
153-
defaultMessage: 'Hello, <name/>',
154-
values: {
155-
name: <b>Jest</b>,
141+
intl
142+
);
143+
144+
const nameNode = rendered.find('b');
145+
expect(nameNode.type()).toBe('b');
146+
expect(nameNode.text()).toBe('Jest');
147+
});
148+
149+
it('supports rich-text message formatting w/ self-closing tag', () => {
150+
const rendered = mountWithProvider(
151+
{
152+
id: 'hello',
153+
defaultMessage: 'Hello, <name/>',
154+
values: {
155+
name: <b>Jest</b>,
156+
},
156157
},
157-
children: (...chunks) => <strong>{chunks}</strong>,
158-
},
159-
intl
160-
);
158+
intl
159+
);
160+
161+
const nameNode = rendered.find('b');
162+
expect(nameNode.type()).toBe('b');
163+
expect(nameNode.text()).toBe('Jest');
164+
});
165+
166+
it('supports rich-text message formatting in function-as-child pattern', () => {
167+
const rendered = mountWithProvider(
168+
{
169+
id: 'hello',
170+
defaultMessage: 'Hello, <name/>',
171+
values: {
172+
name: <b>Jest</b>,
173+
},
174+
children: (...chunks) => <strong>{chunks}</strong>,
175+
},
176+
intl
177+
);
178+
179+
const nameNode = rendered.find('b');
180+
expect(nameNode.type()).toBe('b');
181+
expect(nameNode.text()).toBe('Jest');
182+
});
183+
})
161184

162-
const nameNode = rendered.find('b');
163-
expect(nameNode.type()).toBe('b');
164-
expect(nameNode.text()).toBe('Jest');
165-
});
185+
166186

167187
it('should re-render when `values` are different', () => {
168188
const descriptor = {

0 commit comments

Comments
 (0)