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

'styles' object key always sets its value as an array with Jest testing #1759

Closed
davideasaf opened this issue Aug 27, 2019 · 3 comments
Closed
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: feature

Comments

@davideasaf
Copy link

davideasaf commented Aug 27, 2019

Expected Behavior

When running a Jest test for an Angular application that was setup using the NX workspace, the key styles in any object should be allowed to be mutated.

Current Behavior

Running Jest tests for an Angular application that was setup using the NX workspace, the key styles in an object is always set to an array [].

Failure Information (for bugs)

Steps to Reproduce

  1. Create a brand new nx-workspace with npx create-nx-workspace@8.4.12 test-workspace (I used latest at the time)
  2. Make the below selections:
    1. angular
    2. test-workspace
    3. sass
    4. Yes
    Screen Shot 2019-08-27 at 4 09 26 PM

Screen Shot 2019-08-27 at 4 09 37 PM

  1. Run
cd nx-workspace
  1. Change the apps/test-workspace/src/app/app.component.spec.ts file to only be the below:
describe('BIZARRE TEST', () => {
  it('', () => {
    const foo = { styles: 'hello world' };
    if (Array.isArray(foo.styles)) {
      console.log('THIS SHOULD NOT PRINT');
    }
    console.log('FOO IS:', foo);
    expect(Array.isArray(foo.styles)).toBe(false);
  });
});
  1. Run
yarn test
  1. Result: The test does not pass. This indicates that using styles as an object key always sets the value to [].

Other

  • I have created a minimal Jest application to test if this issue was only relevant for Jest, but the issue was not present in Jest.
  • Repo with above steps reproduced: https://github.com/davideasaf/nx-jest-bug
@vsavkin
Copy link
Member

vsavkin commented Aug 28, 2019

There are two issues here. The first one is that the jest builder always tries to include jest-preset-angular. So it is not possible to opt out. We should fix it.

Second is the actual issue with jest-preset-angular that thinks that all object primitives with "styles" are component decorators. That issue has to be fixed on the jest-preset-angular side.

As a workaround, you can do something like this: const foo = { ['styles']: 'hello world' };.

@vsavkin vsavkin added the scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx label Dec 12, 2019
@jaysoo
Copy link
Member

jaysoo commented Apr 15, 2020

This should have been fixed in jest-preset-angular: thymikee/jest-preset-angular#261

@jaysoo jaysoo closed this as completed Apr 15, 2020
@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: feature
Projects
None yet
Development

No branches or pull requests

3 participants