I’ve just created a fresh Ionic Vue project using Ionic Start and have opened up the vue UI tool and run the Unit Test task. I get the following error:
Did you remove any dependencies from your package.json file? I am not getting that error when running tests with a blank Ionic Vue app.
That being said, the tests in our starter apps should be updated to reference the latest starter components. (I see that they reference a HelloWorld component that no longer exists).
I didn’t remove any dependencies. I just created a new blank Vue project and changed the test file to this:
import { shallowMount } from "@vue/test-utils";
import Home from "@/views/Home.vue";
describe("Home.vue", () => {
it("renders props.msg when passed", () => {
const msg = "new message";
const wrapper = shallowMount(Home, {
props: { msg },
});
expect(wrapper.text()).toMatch(msg);
});
});
If I then open up the Vue UI tool and run the test I get the error:
Test suite failed to run
/Users/user/Projects/myProject/node_modules/@ionic/vue/dist/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { addIcons } from 'ionicons';
^^^^^^
SyntaxError: Cannot use import statement outside a module
23 |
24 | <script lang="ts">
> 25 | import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar } from '@ionic/vue';
| ^
26 | import { defineComponent } from 'vue';
27 |
28 | export default defineComponent({
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/views/Home.vue:25:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Also you will likely need to use mount instead of shallowMount otherwise the test utils will just stub components like ion-page. This is true of a Vue 3 application without Ionic Framework as well.