Skip to content

Commit

Permalink
fix: upgrade intl-messageformat and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
longlho committed Jul 25, 2019
1 parent 6b6477a commit 1dfe7fd
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 53 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"hoist-non-react-statics": "^3.3.0",
"intl-format-cache": "^4.1.2",
"intl-locales-supported": "^1.4.2",
"intl-messageformat": "^5.3.0",
"intl-messageformat": "^5.4.2",
"intl-messageformat-parser": "^2.1.3",
"invariant": "^2.1.1",
"react": "^16.3.0",
Expand Down
2 changes: 1 addition & 1 deletion test/unit/components/html-message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@ describe('<FormattedHTMLMessage>', () => {
intl
).html();

expect(renderedHtml).toBe('<span>Hello, <b>[object Object]</b>!</span>');
expect(renderedHtml).not.toBe('<span>Hello, <b><i>Eric</i></b>!</span>');
});
});
116 changes: 68 additions & 48 deletions test/unit/components/message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,58 +111,78 @@ describe('<FormattedMessage>', () => {
expect(rendered.text()).toBe('Jest');
});

it('supports rich-text message formatting', () => {
const rendered = mountWithProvider(
{
id: 'hello',
defaultMessage: 'Hello, <b>{name}</b>!',
values: {
name: 'Jest',
b: (name: string) => <b>{name}</b>,
describe('rich text', function () {
it('supports legacy behavior', () => {
const rendered = mountWithProvider(
{
id: 'hello',
defaultMessage: 'Hello, {name}!',
values: {
name: <b>Jest</b>,
},
},
},
intl
);

const nameNode = rendered.find('b');
expect(nameNode.type()).toBe('b');
expect(nameNode.text()).toBe('Jest');
});

it('supports rich-text message formatting w/ self-closing tag', () => {
const rendered = mountWithProvider(
{
id: 'hello',
defaultMessage: 'Hello, <name/>',
values: {
name: <b>Jest</b>,
intl
);

const nameNode = rendered.find('b');
expect(nameNode.type()).toBe('b');
expect(nameNode.text()).toBe('Jest');
});
it('supports rich-text message formatting', () => {
const rendered = mountWithProvider(
{
id: 'hello',
defaultMessage: 'Hello, <b>{name}</b>!',
values: {
name: 'Jest',
b: (name: string) => <b>{name}</b>,
},
},
},
intl
);

const nameNode = rendered.find('b');
expect(nameNode.type()).toBe('b');
expect(nameNode.text()).toBe('Jest');
});

it('supports rich-text message formatting in function-as-child pattern', () => {
const rendered = mountWithProvider(
{
id: 'hello',
defaultMessage: 'Hello, <name/>',
values: {
name: <b>Jest</b>,
intl
);

const nameNode = rendered.find('b');
expect(nameNode.type()).toBe('b');
expect(nameNode.text()).toBe('Jest');
});

it('supports rich-text message formatting w/ self-closing tag', () => {
const rendered = mountWithProvider(
{
id: 'hello',
defaultMessage: 'Hello, <name/>',
values: {
name: <b>Jest</b>,
},
},
children: (...chunks) => <strong>{chunks}</strong>,
},
intl
);
intl
);

const nameNode = rendered.find('b');
expect(nameNode.type()).toBe('b');
expect(nameNode.text()).toBe('Jest');
});

it('supports rich-text message formatting in function-as-child pattern', () => {
const rendered = mountWithProvider(
{
id: 'hello',
defaultMessage: 'Hello, <name/>',
values: {
name: <b>Jest</b>,
},
children: (...chunks) => <strong>{chunks}</strong>,
},
intl
);

const nameNode = rendered.find('b');
expect(nameNode.type()).toBe('b');
expect(nameNode.text()).toBe('Jest');
});
})

const nameNode = rendered.find('b');
expect(nameNode.type()).toBe('b');
expect(nameNode.text()).toBe('Jest');
});


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

0 comments on commit 1dfe7fd

Please sign in to comment.