Skip to content

container.snapshot/restore behaviour changed in v7 #1806

@pfe-nazaries

Description

@pfe-nazaries

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

After upgrading from 6.2.1 to 7.5.1 all vitest test that test classes with injectables are broken

I use this pattern to save the original container, rebind with mocks and restore original for each test

beforeEach(() => {
       container.snapshot();

       categoryDatasource = mock<CategoryRemoteDatasource>();

       container
           .rebindSync(CategoryRemoteDatasource)
           .toConstantValue(categoryDatasource);

       categoryRepository = container.get<CategoryRepository>(
           spaTypes.repositories.CategoryRepository,
       );
   });

   afterEach(() => {
       container.restore();
   });

Since the update is like snapshot or restore doesn't work, the container "remains" and "leaks" between test, they are not isolated anymore.

Steps to reproduce

No response

Expected behavior

Each test should get a "fresh" container base of the steps inside beforeEach

Possible solution

No response

Package version

7.5.1

Node.js version

22.15.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Stack trace

No response

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions