Jest在测试期间遇到意外令牌

时间:2020-09-16 07:45:50

标签: javascript vue.js testing jestjs

当尝试为简单的vue.js视图运行Jest测试时,出现有关“ Jest遇到意外令牌”的错误。似乎babel不能正确地编译ScaleLoader,尽管应该?!

没有ScaleLoader,测试将成功运行。我正在使用1.0.4版中的vue-spinner。

=>如何成功运行这些测试而没有错误?

    static void Main()
    {
        if (int.TryParse(Console.ReadLine(), out int iterations))
        {
            //var output = new List<int>();
            var length = iterations;
            var output = new int[length];

            while (iterations > 0) // or iterations > 0 and if number pass then increase the iterations
            {
                if (int.TryParse(Console.ReadLine(), out int number) /*&& number != 0*/ && number % 3 == 0)
                {
                    //outpu.Add(number);
                    output[length - iterations] = number;
                    iterations--;
                }
            }

            Console.WriteLine(string.Join(Environment.NewLine, output));
        }
    }
// inventory_taking.spec.js
import InventoryTaking from "../InventoryTaking.vue";
import {shallowMount} from "@vue/test-utils";

describe("InventoryTaking", () => {
    const wrapper = shallowMount(InventoryTaking);

    it("renders correctly", () => {
        expect(wrapper).toBeTruthy();
    });
});
// InventoryTaking.vue
<template>
</template>

<script>
import ScaleLoader from "vue-spinner/src/ScaleLoader";

export default {
  name: "InventoryTaking",
  components: {
    ScaleLoader,
  },
};
</script>
// Error message
    ● 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:
    
      .../node_modules/vue-spinner/src/ScaleLoader.vue:1
      ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){<template>
                                                                                               ^
    
      SyntaxError: Unexpected token <
    
        3 | 
        4 | <script>
      > 5 | import ScaleLoader from "vue-spinner/src/ScaleLoader";
          | ^
        6 | 
        7 | export default {
        8 |   name: "InventoryTaking",
    
        at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
        at src/views/InventoryTaking.vue:5:1
        at Object.<anonymous> (src/views/InventoryTaking.vue:29:3)

0 个答案:

没有答案