Jest: Unexpected character #

Created on 27 May 2019  路  6Comments  路  Source: facebook/jest

馃悰 Bug Report

A clear and concise description of what the bug is.

I am using private fields in the class and it does not recognize the #

To Reproduce

Steps to reproduce the behavior:

Expected behavior

should have know that this is private field name

A clear and concise description of what you expected to happen.

Link to repl or repo (highly encouraged)

Please provide either a repl.it demo or a minimal repository on GitHub.

https://repl.it/repls/CornsilkMidnightblueGenres

Issues without a reproduction link are likely to stall.

Run npx envinfo --preset jest

Paste the results here:

System:
    OS: Linux 5.0 Ubuntu 19.04 (Disco Dingo)
    CPU: (4) x64 Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
  Binaries:
    Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
    Yarn: 1.16.0 - /usr/bin/yarn
    npm: 6.4.1 - ~/.nvm/versions/node/v10.15.3/bin/npm
  npmPackages:
    jest: 24.7.1 => 24.7.1
Bug Report Needs Repro Needs Triage

Most helpful comment

Thank you @SimenB !

Setting transform: {} in jest.config.js did the trick!

All 6 comments

You will have to configure Babel to transpile syntax that is not yet supported natively by Node, please check out the docs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

This article (which predates this ticket) suggests that private fields are in-fact supported in the latest version of node.
https://thecodebarbarian.com/nodejs-12-private-class-fields.html

Indeed, I have tested it. I have created a class that has a private field and a method that returns it. I can print it to the console. Yet requiring it in a jest test throws a syntax error.

Here's a small github project that demonstrates the issue. My node version is v12.4.0
https://github.com/musicin3d/jest-bug

This is essentially https://github.com/facebook/jest/issues/6829, just another syntax. You'll need to configure babel or disable babel-jest for this to work

Thank you @SimenB !

Setting transform: {} in jest.config.js did the trick!

@SimenB yeah, it works! Thanks :-D

Was this page helpful?
0 / 5 - 0 ratings