Reputation: 11
I'm invoking Telegram Bot API from a Node.js
application. I need to send some Unicode characters to the API, that only accepts Ruby format (\u{1F680}
outputs 🚀 ). I store all Unicode characters in this format in a file that is required by the one actually sending the message to the API.
Node.js is ok with this, it's working fine. However, when I run Mocha tests on the same code, it results in an Unexpected token ILLEGAL
error, it doesn't like the Ruby Unicode format. The test itself isn't even using this Unicode character, the compilation is what fails.
emojis.rocket = '\u{1F680}';
^^^
SyntaxError: Unexpected token ILLEGAL
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/path/to/file/values_es.js:1:76)
// more error lines...
npm ERR! Test failed. See above for more details.
If I change it to the JavaScript Unicode format (\u1F680
), Mocha and Node.js are OK with it, but the API doesn't get it as the appropriate character.
I've tried the following:
\u1F680
and then adding the {}
in runtime, but it outputs a different character (Ὠ0), corresponding to the first four HEX values (\u1F68
) and the extra 0
.\u1F680
and adding encode Ruby function code.encode('UTF-8')
just in case Telegram Bot API executes Ruby code. Not working either, it prints \u1F680.encode('UTF-8')
.Is there any way in which I can make Mocha accept Ruby-ish (\u{1F680}
) format?
Upvotes: 1
Views: 184
Reputation: 24617
Use the RegExp constructor to pass it through the mocha test:
RegExp('\u{1F680}')
then use exec
and toString
to convert it to a string:
RegExp('\u{1F680}').exec('\u{1F680}').toString()
References
Upvotes: 0