Проблема с шуткой - «шутка обнаружила неожиданный токен» - PullRequest
0 голосов
/ 05 мая 2020

У меня проблема с Jest. Когда я вызываю npm test, я получаю в терминале следующий код:

    > jest

  FAIL  src/client/js/splitobject.test.js
  ● Test suite failed to run

    Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain 
  JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring 
 "node_modules".

    Here's what you can do:
     • To have some of your "node_modules" files transformed, you can specify a custom 
 "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the 
 "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/en/configuration.html

    Details:

    C:\Users\Amir\Desktop\evaluate-news-nlp\src\client\styles\base.scss:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){body {     
                                                                                                  ^     

    SyntaxError: Unexpected token '{'

      1 | // Import statements
    > 2 | import '../styles/base.scss'
        | ^
      3 | import '../styles/footer.scss'
      4 | import '../styles/form.scss'
      5 | import '../styles/header.scss'

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1258:14)
      at Object.<anonymous> (src/client/js/index.js:2:1)

 Test Suites: 1 failed, 1 total
 Tests:       0 total
 Snapshots:   0 total
 Time:        4.67s
 Ran all test suites.
 npm ERR! Test failed.  See above for more details.

testfile splitobject.test. js:

    import splitObject from './index.js'

let list = {
    text: `McFoible sang happily to himself. The sun was shining.`,
    language: 'en',
    hashtags: [
        'first',
        'second',
        'third',
        'fourth',
        'fifth',
        'sixth'
    ]
}

test('Properly split the object', () => {
    expect(splitObject(list).toEqual([
        `McFoible sang happily to himself. The su...`,
        'en',
        [
            'first',
            'second',
            'third',
            'fourth',
            'fifth',
            'sixth'
        ]
    ]))
})

Кто-нибудь знает, как исправить этот? Если я правильно понял, файл index. js, в котором находится функция, которую я хочу протестировать, имеет некоторые файлы импорта (файлы .s css), и они, в свою очередь, имеют {которые не могут быть прочитаны по какой-то причине. Как мне обойти эту проблему?

Мне было трудно осознать это.

Заранее спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...