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

The Sociable API fails to function when class constructor is left empty of params #509

Closed
2 of 4 tasks
kostyazgara opened this issue Nov 25, 2024 · 2 comments
Closed
2 of 4 tasks
Assignees
Labels
bug Something isn't working

Comments

@kostyazgara
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

The new Sociable API is not working properly. I tried to setup a minimal reproducible example in my repo.

const { unit, unitRef } = await TestBed.sociable(TestService).expose(TestSociableService).compile();
const testDependService = unitRef.get(TestDependService);

unit.test();
expect(testDependService.call).toHaveBeenCalledWith(true); // returns undefined, but should true

Minimum reproduction code

https://github.com/KostyaZgara/suites-expose-reproduce

Steps to reproduce

  • Clone repo
  • run npm i
  • run npm run test-ts or npm run test-swc

Expected behavior

return method should not be mocked when exposing the class TestSociableService using .expose() API in sociable test. I'm expecting to have success assert check expect(testDependService.call).toHaveBeenCalledWith(true)

Suites version

"@suites/di.nestjs": "3.0.0", "@suites/doubles.jest": "3.0.0", "@suites/unit": "3.0.0",

Node.js version

20.11.1

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@omermorad
Copy link
Collaborator

Hey @kostyazgara

I reviewed the example repository.
While the test flow deviates slightly from the usual Suite structure, you are correct.

I’ve added an additional class named FooClass, which TestSociableService relies on:

import { Injectable } from '@nestjs/common';
import { FooClass } from './foo-class';

@Injectable()
export class TestSociableService {
  public constructor(private readonly foo: FooClass) {}

  public return(): boolean {
    return true;
  }
}

This is the spec (test) file:

describe('Test', () => {
  let testDependService: Mocked<TestDependService>;
  let underTest: TestService;

  beforeAll(async () => {
    const { unit, unitRef } = await TestBed.sociable(TestService)
      .expose(TestSociableService)
      .compile();

    underTest = unit;

    testDependService = unitRef.get(TestDependService);

    underTest.test();
  });

  it('should expose sociable service',() => {
    expect(testDependService.call).toHaveBeenCalledWith(true);
  });
})

When I include FooClass in the constructor of TestSociableService, everything works correctly, but upon its removal, the test does not pass.

import { Injectable } from '@nestjs/common';
import { FooClass } from './foo-class';

@Injectable()
export class TestSociableService {
  // When I remove the constructor param, the test fails
  public constructor(private readonly foo: FooClass) {}

  public return(): boolean {
    return true;
  }
}

We will investigate this further, as it appears to be an edge case. I will provide an update soon, although it may take some time to resolve.

Thank you for posting this 🙏🏻

@omermorad omermorad added the bug Something isn't working label Nov 26, 2024
@omermorad omermorad changed the title Sociable API is not working The Sociable API fails to function whe class constructor is left empty of params Nov 26, 2024
@omermorad omermorad changed the title The Sociable API fails to function whe class constructor is left empty of params The Sociable API fails to function when class constructor is left empty of params Nov 26, 2024
@omermorad
Copy link
Collaborator

Released in v3.0.1 (@kostyazgara).

@craig0990 🚀

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

No branches or pull requests

3 participants