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.