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

29 lines
838 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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("братьев"));\
';
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}: ",
"братьев",
]
});
});