• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

153
Views
Vue: Mixin in Unit Test causes weird test failure

I am attempting to add some unit tests to a component that has a mixin.

Here is roughly what the mixin is doing:

import test from '@/assets/file.txt'

export default {
  data() {
    return {
      title: '',
      body: ''
    }
  },
  methods: {
    initData() {
      // Read data from the file and update data() above.
    }
  }
}

The only seemingly relevant line in this mixin causing the error is the import. It is throwing a SyntaxError as follows:

SyntaxError: Invalid left-hand side expression in prefix operation

> 1 | import alertTuning from '@/assets/AlertTuning.md'
    | ^
  2 |
  3 | export default {
  4 |   data() {

  at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
  at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
  at Object.<anonymous> (src/assets/js/mixins/alertTuningTemplateMixin.js:1:1)

This strikes me as weird because I know this is syntactically correct JavaScript, why would this import be throwing such an error only when unit testing it?

The mixin works perfectly outside of testing scenarios, i.e. in our local, prod, and stage website it works perfectly without any errors.

Thanks.

almost 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error