Skip to content

Commit

Permalink
refactor(macro): add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timofei-iatsenko committed Jan 6, 2023
1 parent 53d2844 commit 82983a6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/macro/test/jsx-plural.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,41 @@ const cases: TestCase[] = [
}} />;
`,
},
{
name: 'Should preserve reserved props: `comment`, `context`, `render`, `id`',
input: `
import { Plural } from '@lingui/macro';
<Plural
comment="Comment for translator"
context="translation context"
id="custom.id"
render={() => {}}
value={count}
offset="1"
_0="Zero items"
few={\`\${count} items\`}
other={<a href="/more">A lot of them</a>}
/>;
`,
expected: `
import { Trans } from "@lingui/react";
<Trans
render={() => {}}
id="custom.id"
message={
"{count, plural, offset:1 =0 {Zero items} few {{count} items} other {<0>A lot of them</0>}}"
}
comment="Comment for translator"
context="translation context"
values={{
count: count
}}
components={{
0: <a href="/more" />
}}
/>;
`,
},
{
input: `
import { Trans, Plural } from '@lingui/macro';
Expand Down
22 changes: 22 additions & 0 deletions packages/macro/test/jsx-trans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@ const cases: TestCase[] = [
<Trans id="msg.hello" message={"Hello World"} />;
`,
},
{
name: 'Should preserve reserved props: `comment`, `context`, `render`, `id`',
input: `
import { Trans } from '@lingui/macro';
<Trans
comment="Comment for translator"
context="translation context"
id="custom.id"
render={() => {}}
>Hello World</Trans>;
`,
expected: `
import { Trans } from "@lingui/react";
<Trans
render={() => {}}
id="custom.id"
message={"Hello World"}
comment="Comment for translator"
context="translation context"
/>;
`,
},
{
name: "Macro without children is noop",
input: `
Expand Down

0 comments on commit 82983a6

Please sign in to comment.