Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSR support #1218

Closed
flsion opened this issue Jan 5, 2022 · 2 comments
Closed

SSR support #1218

flsion opened this issue Jan 5, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@flsion
Copy link

flsion commented Jan 5, 2022

Basic Info

"vue": "^3.2.0",
"jest": "^26.6.3",
"vue-jest": "^5.0.0-alpha.10"
"@vue/test-utils": "^2.0.0-beta.14",

Problem

When I set the testEnvironment: 'node' of jest, the mount function will report ReferenceError: document is not defined. How should I configure ssr?

Config

{
      transform: {
        '^.+\\.[jt]sx?$': require.resolve('babel-jest'),
        '^.+\\.vue$': require.resolve('vue-jest'),
      },
      testEnvironment: 'node',
}

Test

import { mount } from '@vue/test-utils';
import Button from '../index';

describe('Button', () => {
  test('should emit click event', () => {
    const wrapper = mount(Button);
    wrapper.find('button').trigger('click');

    expect(wrapper.emitted('click')).toHaveLength(1);
  });

  test('should not emit click event when disabled', () => {
    const wrapper = mount(Button, {
      props: {
        disabled: true,
      },
    });
    wrapper.find('button').trigger('click');

    expect(wrapper.emitted('click')).toBeUndefined();
  });
});
@lmiller1990
Copy link
Member

We will need to implement something like https://vue-test-utils.vuejs.org/api/#rendertostring from VTU v1, I think. We don't have any test coverage or examples around SSR at all yet.

Is this something you'd like to explore? The implementation in VTU v1 is pretty simple.

@cexbrayat
Copy link
Member

Duplicates of #507

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants