Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript (Vue.js | Jest | Babel)导入特定Vue文件时出现意外标记_Javascript_Vue.js_Jestjs_Babeljs - Fatal编程技术网

Javascript (Vue.js | Jest | Babel)导入特定Vue文件时出现意外标记

Javascript (Vue.js | Jest | Babel)导入特定Vue文件时出现意外标记,javascript,vue.js,jestjs,babeljs,Javascript,Vue.js,Jestjs,Babeljs,我正在导入一个vue文件,该文件中只有脚本,只有模板标记 然后我导入js文件以帮助我完成所需的工作 在这最后的导入中,问题是(我认为),但就是这个文件,因为我已经用另一个文件进行了测试并通过了测试 PS:对不起我的新手问题和我的英语,这是我的第一个问题。谢谢你的关注 sales.test.js import ApexChart from 'vue-apexcharts' import BootstrapVue from 'bootstrap-vue' import sinon from 'sin

我正在导入一个vue文件,该文件中只有脚本,只有模板标记
然后我导入js文件以帮助我完成所需的工作
在这最后的导入中,问题是(我认为),但就是这个文件,因为我已经用另一个文件进行了测试并通过了测试

PS:对不起我的新手问题和我的英语,这是我的第一个问题。谢谢你的关注

sales.test.js

import ApexChart from 'vue-apexcharts'
import BootstrapVue from 'bootstrap-vue'
import sinon from 'sinon'
import { shallowMount, createLocalVue } from '@vue/test-utils'

import salesPage from '../src/views/vendas/Vendas'
package.json

"jest": {
    "moduleFileExtensions": [
      "js",
      "vue"
    ],
    "moduleNameMapper": {
      "^@/(.*)$": "<rootDir>/src/$1"
    },
    "transform": {
      "^[^.]+.(vue|jsx)$": "vue-jest",
      "^.+\\.(js|jsx)$": "babel-jest"
    },
    "snapshotSerializers": ["jest-serializer-vue"]
  }
functions.js

'use strict'

import moment from 'moment'

export function dateFormatter(date) {
  return moment(date).format('DD/MM/YYYY')
}

export function changeInitialDate(date) {
  if (date) {
    this.disabledDatesEnd = null
    this.disabledDatesEnd = new Object()
    this.disabledDatesEnd.to = new Date(date)
  }
}

export function changeFinalDate(date) {
  if (date) {
    this.disabledDatesStart = null
    this.disabledDatesStart = new Object()
    this.disabledDatesStart.from = new Date(date)
  }
}

export function cnpjFormatter(cnpj) {
  return cnpj.toString().replace(/[^0-9a-zA-Z]+/g, '')
}
错误


它可能是导入中的尾随逗号吗

由此:

import{changeFinalDate,cnpjFormatter,}来自“./../functions”;
^
为此:

import { changeFinalDate, cnpjFormatter } from "../../functions";

如果您可以共享
函数
文件夹中的文件,这将很有帮助:)这是可行的,但现在我在组件名称中出现了另一个错误,例如:导出默认值{name:'Vendas'->意外标记,应为“}”,请尝试从导入语句中删除大括号。据我所知,只有在js中使用
defaults
标志导出函数时,才会在导入时使用大括号。因此,请尝试:
从“../../functions”导入changeFinalDate、cnpjFormatter
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:

    SyntaxError: /home/victor/development/accesys/AccCRM/Sources/cliente-web-clientes/unknown: Unexpected token (16:0)

      14 |   changeFinalDate,
      15 |   cnpjFormatter,
    > 16 | } from "../../functions";
         | ^
      17 | 
      18 | import {
      19 |   onClassChange,

      at Object._raise (node_modules/@babel/parser/src/parser/error.js:60:45)
      at Object.raiseWithData (node_modules/@babel/parser/src/parser/error.js:55:17)
      at Object.raise (node_modules/@babel/parser/src/parser/error.js:39:17)
      at Object.unexpected (node_modules/@babel/parser/src/parser/util.js:139:16)
      at Object.parseExprAtom (node_modules/@babel/parser/src/parser/expression.js:1186:20)
      at Object.parseExprAtom (node_modules/@babel/parser/src/plugins/jsx/index.js:535:22)
      at Object.parseExprSubscripts (node_modules/@babel/parser/src/parser/expression.js:563:23)
      at Object.parseUpdate (node_modules/@babel/parser/src/parser/expression.js:543:21)
      at Object.parseMaybeUnary (node_modules/@babel/parser/src/parser/expression.js:527:17)
      at Object.parseExprOps (node_modules/@babel/parser/src/parser/expression.js:343:23)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.524s
import { changeFinalDate, cnpjFormatter } from "../../functions";