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

Cannot access '__vite_ssr_import_2__' before initialization #96

Closed
sysmat opened this issue Mar 21, 2023 · 5 comments
Closed

Cannot access '__vite_ssr_import_2__' before initialization #96

sysmat opened this issue Mar 21, 2023 · 5 comments

Comments

@sysmat
Copy link

sysmat commented Mar 21, 2023

  • Test stop working after update:
 vite                  ^4.2.0  →   ^4.2.1
 vitest               ^0.29.3  →  ^0.29.7
@solidjs/router  ^0.8.0 →  ^0.8.1
  • error
 FAIL  src/pages/Planets.test.tsx [ src/pages/Planets.test.tsx ]
ReferenceError: Cannot access '__vite_ssr_import_2__' before initialization
 ❯ src/pages/Planets.test.tsx:2:1
      1| 
      2| 
       | ^
      3| import { render } from '@solidjs/testing-library';
      4| import { afterEach, describe, expect, it, vi } from 'vitest';
  • test
import { render } from '@solidjs/testing-library';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { Planet, Result } from '../shared/service';
import PlanetsC from './Planets';

vi.mock('../shared/service', async () => {

  const planet: Planet =
  {
    name: 'tom',
    rotation_period: 12,
    orbital_period: 71,
    diameter: 678,
    gravity: 'strong',
    terrain: 'jungle'
  };

  const planets: Planet[] = [planet];

  const planetsR: Result<Planet> = {
    next: '',
    previous: '',
    count: 1,
    results: planets
  };

  const fetchPlanets = vi.fn();
  fetchPlanets.mockReturnValue(Promise.resolve(planetsR));

  return { fetchPlanets }
});

describe('Planets component', () => {

  afterEach(async () => {
    await vi.restoreAllMocks();
  })

  it('should mock some data', async () => {
    const { findByText } = render(() => <PlanetsC />);
    // column names
    expect(await findByText('Name', { exact: false })).toBeDefined();
    expect(await findByText('rotation_period', { exact: false })).toBeDefined();
    expect(await findByText('orbital_period', { exact: false })).toBeDefined();
    expect(await findByText('diameter', { exact: false })).toBeDefined();
    expect(await findByText('gravity', { exact: false })).toBeDefined();
    expect(await findByText('terrain', { exact: false })).toBeDefined();
    expect(await findByText('Action', { exact: false })).toBeDefined();
    // column values
    expect(await findByText('tom', { exact: false })).toBeDefined();
    expect(await findByText('12', { exact: false })).toBeDefined();
    expect(await findByText('71', { exact: false })).toBeDefined();
    expect(await findByText('678', { exact: false })).toBeDefined();
    expect(await findByText('strong', { exact: false })).toBeDefined();
    expect(await findByText('jungle', { exact: false })).toBeDefined();
  });
});
@sysmat
Copy link
Author

sysmat commented Mar 23, 2023

@sysmat
Copy link
Author

sysmat commented Apr 10, 2023

  • any progress?
  • even with updates error still persiste
solid-js                         ^1.7.0  →   ^1.7.3
 typescript                       ^5.0.3  →   ^5.0.4
 vite-plugin-solid                 2.6.1  →    2.7.0
 vitest                          ^0.29.8  →  ^0.30.0

@shishkin
Copy link

Try setting vitest globals and remove the import line import { afterEach, describe, expect, it, vi } from 'vitest';. That solved it for me after reading this issue comment.

@sysmat
Copy link
Author

sysmat commented Apr 15, 2023

@shishkin thx, but this is kind a bad, but it works

@sysmat sysmat closed this as completed Apr 15, 2023
@shishkin
Copy link

@shishkin thx, but this is kind a bad, but it works

I don't disagree. That's an issue for vitest however, not specific to solid.

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

No branches or pull requests

2 participants