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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[swc-angular-plugin] Issue with inherited classes #376

Open
santiagof4 opened this issue May 8, 2024 · 0 comments
Open

[swc-angular-plugin] Issue with inherited classes #376

santiagof4 opened this issue May 8, 2024 · 0 comments
Labels
bug Something isn't working swc-angular

Comments

@santiagof4
Copy link

Hello!

First of all, thanks a lot for the effort! This plugin has already incredible results in our huge project with more than 2000 tests.

The issue

When running our tests with plain Jest, everything works (but super slow 馃槈), but when running our tests with swc-angular this issue arises:

Looks like classes that extend from other class lose values of those properties that are not present in the parent class.

Example:

interface IModelBase {
  id?: string;
  name: string;
}

class ModelBase implements IModelBase {
  id?: string;
  name: string;

  constructor(model: Partial<IModelBase>) {
    Object.assign(this, model);
  }
}

interface IModel {
  version: number;
}

export class Model extends ModelBase implements IModel {
  version: number;

  constructor(model: Partial<IModel & IModelBase>) {
    super(model);
  }
}

When testing something with that class, version is always undefined:

import { Model } from './model';

describe("failing class tests", () => {
  it('should init class with all the values', () => {
    const model = new Model({ id: '123', name: 'test', version: 1 });

    expect(model.id).toEqual('123');
    expect(model.name).toEqual('test');
    expect(model.version).toEqual(1); // This fails, 'version' is undefined
  })
})

This also works with Jasmine and in normal runtime.

Reproduction

https://github.com/santiagof4/jest-angular-swc-class-reproduction

  1. clone package
  2. npm install
  3. nx test
  4. Test in https://github.com/santiagof4/jest-angular-swc-class-reproduction/blob/main/src/app/failing-test.spec.ts fails.
@edbzn edbzn added bug Something isn't working swc-plugin-angular labels May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working swc-angular
Projects
None yet
Development

No branches or pull requests

2 participants