Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

fix: Jest tests are inaccurate since v.0.23.0 #468

Closed
tommycoppers opened this issue Apr 27, 2021 · 0 comments · Fixed by #470
Closed

fix: Jest tests are inaccurate since v.0.23.0 #468

tommycoppers opened this issue Apr 27, 2021 · 0 comments · Fixed by #470
Assignees
Labels
bug Something isn't working

Comments

@tommycoppers
Copy link

tommycoppers commented Apr 27, 2021

🐛 The bug
Upgrading to version v.0.23.0 (https://github.com/nuxt-community/composition-api/releases/tag/0.23.0) breaks testing with Jest. Namely, the setup() function in a component is never being called. Note that the application works as expected. It's only the tests that are showing odd behavior.

My assumption is that the 'auto-mock' is not working as expected, outside a Nuxt context. Hoping someone can help!

I've followed the release notes to update my app to do the following:

nuxt.config

FROM:

  buildModules: ['@nuxtjs/composition-api'],

TO:

  buildModules: ['@nuxtjs/composition-api/module'],

jest.config

FROM:

moduleNameMapper: {
   // ...
  '@nuxtjs/composition-api': '@nuxtjs/composition-api/entrypoint',
},

TO:

moduleNameMapper: {
   // ...
},

With the upgrade, nothing in the setup() method is being executed, however, the component still compiles. If i reorganized a dummy component to use a data prop, for example, the tests would attach the value to mounted compnent's vm property.

🛠️ To reproduce
Steps to reproduce the behavior:

  1. Install version v0.22.4
  2. Add the composition api to your buildModules ( buildModules: ['@nuxtjs/composition-api'],)
  3. Add the entrypoint to the moduleNameMapper ( '@nuxtjs/composition-api': '@nuxtjs/composition-api/entrypoint',)
  4. Write a dummy component with a setup function that returns an object with some key/value pairs (`setup(){ return {foo:'bar'} }
  5. Write a dummy test for the component. Console log a value that was returned by the components setup() method. Example
import { mount, createLocalVue } from '@vue/test-utils';
import foobar from './foobar.vue';

const localVue = createLocalVue();
describe('foobar', () => {
  test('renders correctly', () => {
    const wrapper = mount(foobar, {
      localVue,
    });

    console.log(`>>> wrapper.vm.foo <<<\n`, wrapper.vm.foo);

    expect(wrapper.vm.foo).toBe('bar')
  });
});
  1. Observe a passing test and a printed value of 'bar'
  2. Install version v0.23.0
  3. Update the buildModules in nuxt.config (buildModules: ['@nuxtjs/composition-api/module'],)
  4. Remove the moduleNameMapper from jest.config
  5. Repeat steps 4-5 (or just rerun the test)
  6. Observe test fail and a printed value of undefined

🌈 Expected behaviour
I expected that the tests that passed prior to the upgrade would also pass after the upgrade.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants