babel-plugin-react-translate/__tests__/index-test.js

35 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2021-08-28 16:34:45 +03:00
const fs = require('fs');
const babel = require('@babel/core');
const jsx = require('@babel/plugin-transform-react-jsx');
const plugin = require('../');
var example = '\
var name = "John";\
var foo = "Ё-Mobile";\
foo = "Меня зовут "+name+"! ";\
foo = ` Меня зовут ${name}!`;\
foo = <span>Привет!</span>;\
foo = L("У меня много {1}: ", L("братьев"));\
var age = { "Братья": { "Иван": "Горький", "Mikhail": "Золотухин" }, ["Сёстры"+getnum()]: {}, Родители };\
2021-08-28 16:34:45 +03:00
';
it('works', () =>
{
const { code } = babel.transform(example, { filename: 'test', plugins: [ jsx, plugin ] });
expect(code).toMatchSnapshot();
expect(JSON.parse(fs.readFileSync('react-translate-output.json'))).toEqual({
test: [
"Ё-Mobile",
"Меня зовут {1}!",
"Привет!",
"У меня много {1}: ",
"братьев",
2021-11-08 00:39:35 +03:00
"Братья",
"Иван",
"Горький",
"Золотухин",
2021-11-08 00:39:35 +03:00
"Сёстры{1}"
2021-08-28 16:34:45 +03:00
]
});
});