@posva/pinia runs unit tests properly, but throws jest warnings and ts errors
See original GitHub issueReproduction
yarn add @posva/pinia
test.spec.ts
it("calls a function from store", () => {
// eslint-disable-next-line
// @ts-ignore <--- by the way, the typescript error happens here: global does not exist on type...
const wrapper = shallowMount(App, { global: { plugins: [createTestingPinia()] } });
// defined outside
const store = useStore();
wrapper.vm.$router.onReady(async () => {
expect(store.fetchList).toHaveBeenCalled();
// test succeeded
});
});
Warnings from @vue/test-utils
[Vue warn]: Injection "Symbol(pinia)" not found
TS error for global
property:
Object literal may only specify known properties, and 'global' does not exist in type 'FunctionalComponentShallowMountOptions<Vue>'
Steps to reproduce the behavior
- Define a store using
defineStore
- Define an action in
actions
- Create a testing file
test.spec.ts
- Write a test similar to above using Vue 2 environment that is described above
- See the warning/ts-error
Expected behavior
No TS error, no jest warnings
Actual behavior
TS throws an error on using global
prop within shallowMount
method from @vue/test-utils
Jest throws warnings [Vue warn]: Injection "Symbol(pinia)" not found
Additional information
Env:
“@pinia/testing”: “0.0.2”, “pinia”: “0.5.4”, “vue”: “2.6.14”,
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
@posva/pinia runs unit tests properly, but throws jest warnings ...
@posva I have just added pinia v2 in Vue 2 project, and I receive TS errors in my tests like Object literal may...
Read more >How to test a function that's expected to throw error in jest…
This caused the error I was getting. Here are the correct ways to write the unit tests: Based on the warning on the...
Read more >How to test the type of a thrown exception in Jest
My current testing framework is AVA and I can test it as a second argument t.throws method, like here: it('should throw Error with...
Read more >Catch warnings in Jest tests | Ben Ilegbodu
These warnings typically show up when running unit tests as well. ... Jest tests fail whenever an error is thrown (and not caught), ......
Read more >Troubleshooting - Jest
Troubleshooting. Uh oh, something went wrong? Use this guide to resolve issues with Jest. Tests are Failing and You Don't Know Why.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh well, that’s pretty neat it just works! The type issue needs to be fixed #630, it shouldn’t be a necessary step for users. Ideally without any extra type file, mixing Vue 3 and Vue 2 types together, if that’s not an issue for TypeScript. If that’s not possible, having a separate file for Vue 2 types would be enough
pinia/vue-2-types
. I will still have to think about it but I’m open to proposalsCurrently,
@pinia/testing
only officialy supports Vue 3. For Vue 2, You need pinia@2 (it works with Vue 2 but devtools need an upstream fix) and to adapt your tests to use the vue-test-utils for Vue 2 too.I added this to my list of things to document for the testing pinia but I haven’t even tested it yet so it might require some changes to
@pinia/testing
. Based on https://vue-test-utils.vuejs.org/api/options.html#other-options, you probably needFeel free to PR if you find anything missing/broken.