笑话问题-“笑话遇到了意外的令牌”

时间:2020-05-04 21:44:44

标签: javascript testing jestjs babeljs

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.

测试文件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文件有一些导入文件(.scss文件),而它们又有{由于某种原因无法读取。我如何解决这个问题?

我发现很难缠住它。

谢谢。

0 个答案:

没有答案