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 set property ɵprov of function AbstractTuiDialogService(idService) #1257

Closed
1 of 9 tasks
robingenz opened this issue Jan 25, 2022 · 20 comments
Closed
1 of 9 tasks
Assignees
Labels
P3 This issue has low priority

Comments

@robingenz
Copy link
Contributor

Which @taiga-ui/* package(s) are the source of the bug?

core

Please provide a link to a minimal reproduction of the bug

https://github.com/robingenz/taiga-ui-issue-1257

Description

Hi, first of all thanks for this great library.
I have the following issue:
When I want to test a component or service that injects the TuiNotificationsService, I get the following error:

 FAIL  src/app/home/home.component.spec.ts
  ● Test suite failed to run

    TypeError: Cannot set property ɵprov of function AbstractTuiDialogService(idService) {
                var _this = _super.call(this, function (observer) { ...<omitted>... } which has only a getter

      1 | import { ComponentFixture, TestBed } from '@angular/core/testing';
    > 2 | import { TuiNotificationsService } from '@taiga-ui/core';
        | ^
      3 | import { createSpyObj } from 'src/tests/helpers';
      4 |
      5 | import { HomeComponent } from './home.component';

      at node_modules/@taiga-ui/core/bundles/taiga-ui-core-components-dialog.umd.js:402:32
      at node_modules/@taiga-ui/core/bundles/ng:/@taiga-ui/core/components/dialog/dialog.service.ts:24:2
      at node_modules/@taiga-ui/core/bundles/taiga-ui-core-components-dialog.umd.js:2:68
      at Object.<anonymous> (node_modules/@taiga-ui/core/bundles/taiga-ui-core-components-dialog.umd.js:5:2)
      at node_modules/@taiga-ui/core/bundles/taiga-ui-core-components.umd.js:2:222
      at Object.<anonymous> (node_modules/@taiga-ui/core/bundles/taiga-ui-core-components.umd.js:5:2)
      at node_modules/@taiga-ui/core/bundles/taiga-ui-core.umd.js:2:156
      at Object.<anonymous> (node_modules/@taiga-ui/core/bundles/taiga-ui-core.umd.js:5:2)
      at Object.<anonymous> (src/app/home/home.component.spec.ts:2:1)
      at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
      at runJest (node_modules/@jest/core/build/runJest.js:404:19)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.672 s
Ran all test suites related to changed files.

Watch Usage: Press w to show more.

For testing, I use Jest.

Is there anything in particular that needs to be imported for the tests or have I missed anything else?

Angular version

13.1.0

Taiga UI version

2.31.0

Which browsers have you used?

  • Chrome
  • Firefox
  • Safari
  • Edge

Which operating systems have you used?

  • macOS
  • Windows
  • Linux
  • iOS
  • Android
@robingenz robingenz added the bug label Jan 25, 2022
@waterplea
Copy link
Collaborator

You don't need to import anything, it should work. That is very strange, notifications are unrelated to dialogs. Can you make a little repository with reproduction?

@splincode
Copy link
Member

@robingenz
Copy link
Contributor Author

Thanks @splincode, was just about to write it. 😄 @waterplea Thank you for your fast response. Please let me know if you need more information.

@waterplea
Copy link
Collaborator

Ops, sorry, missed the link somehow )

@syrok0010
Copy link

syrok0010 commented Jan 29, 2022

Also have this error. Thought that it was a problem with ng-mocks. But now believe it's not.
help-me-mom/ng-mocks#1711

@robingenz
Copy link
Contributor Author

My biggest problem at the moment is that I can't use TuiNotificationsService at all, otherwise even my previous tests won't run anymore, since the TypeError is thrown immediately as soon as any other test has a reference to TuiNotificationsService.
First I thought I simply forgot to import a module, but according to #1257 (comment) it should work without import.

@waterplea
Copy link
Collaborator

Could it be something like this where compiler tries to compile service multiple times for some reason?
angular/angular#35993
Maybe there is some sort of optimization for tests in place that fails 🤔 I also found this which has no solution but is very similar in terms of dealing with decorated abstract class:
https://stackoverflow.com/questions/60633963/angular-9-production-error-cannot-set-property-%C9%B5fac-of-abstract-class-myfilte
This article seems to suggest a solution, but I haven't tried it yet:
https://qiita.com/yuma-ito-bd/items/cd32cb57e13f56b59f18
Running jest with no cache: $ jest hero.service --no-cache (could be relevant considering the first link I've mentioned) and adding "emitDecoratorMetadata": true to tsconfig.spec.ts.

@syrok0010
Copy link

syrok0010 commented Jan 31, 2022

Unfortunately, neither jest --no-cache nor editing the tsconfig fixes the issue for me

@robingenz
Copy link
Contributor Author

@waterplea Thank you for your time.

Could it be something like this where compiler tries to compile service multiple times for some reason? angular/angular#35993

I don't think so. The production build works fine and enabling/disabling optimizations does not bring any change.

I have tried both: Added "emitDecoratorMetadata": true and run Jest with --no-cache.
Unfortunately, the error persists.

@satanTime
Copy link

satanTime commented Jan 31, 2022

Looks like this version of taiga:

    "@taiga-ui/addon-mobile": "^2.31.0",
    "@taiga-ui/cdk": "^2.31.0",
    "@taiga-ui/core": "^2.31.0",
    "@taiga-ui/icons": "^2.31.0",
    "@taiga-ui/kit": "^2.31.0",

isn't compatible with jest on angular 13 well (perhaps wrong ivy build / config).

I've fixed your issue by running npx ngcc before running tests.

@robingenz
Copy link
Contributor Author

I've fixed your issue by running npx ngcc before running tests.

I can confirm this.

@satanTime Thank you very much for your help!

@waterplea
Copy link
Collaborator

All current versions of Taiga require ngcc, it's weird that tests don't do this automatically 🤔

@satanTime
Copy link

satanTime commented Feb 1, 2022

as a guess, maybe the problem is in @angular-builders/jest:run and it doesn't trigger ngcc before its execution.

a way to check:
on a fresh clone of https://github.com/robingenz/taiga-ui-issue-1257 where ngcc hasn't been executed yet,
to try to run tests with standard @angular-devkit/build-angular:karma instead of jest.

if it triggers ngcc, then a fix should be done in @angular-builders/jest:run.
I'll try to check it next days.

@waterplea waterplea added P3 This issue has low priority and removed state: need triage labels Feb 1, 2022
@waterplea
Copy link
Collaborator

Giving it a P3 since it's probably not an issue with Taiga UI and I don't think there's much we can do. Adding some hacks in Taiga UI to run ngcc on postinstall seems a bit extreme to me, besides we want to migrate to Angular 12 in the next major release that we are working on anyway.

@satanTime
Copy link

Agree. Sounds like a talk for a runner and not a lib

@splincode
Copy link
Member

@robingenz Hello, try add "postinstall": "ngcc --async" here https://github.com/robingenz/taiga-ui-issue-1257/blob/main/package.json#L4

@robingenz
Copy link
Contributor Author

Thank you all for your help.

Hello, try add "postinstall": "ngcc --async" here robingenz/taiga-ui-issue-1257@main/package.json#L4

I have already added this exact line to my actual project and it works very well. So this is a good workaournd.

@the-ult
Copy link

the-ult commented Jun 9, 2022

Same issue still occurs with Angular 13/14

Even when using the postinstall: "ngcc ...." script (which is default when using Nx

@spicy-tomato
Copy link
Contributor

Same issue still occurs with Angular 13/14

Even when using the postinstall: "ngcc ...." script (which is default when using Nx

Same issue here :/

@zy2ba
Copy link
Contributor

zy2ba commented Jan 12, 2023

Meets same issue after update to Angular 13 & nx 13. For me resolved by adding
globalSetup: 'jest-preset-angular/global-setup',
to jest config

@waterplea waterplea closed this as not planned Won't fix, can't repro, duplicate, stale Aug 2, 2023
@github-project-automation github-project-automation bot moved this to 💡 Backlog in Taiga-family Sep 26, 2023
@splincode splincode moved this from 💡 Backlog to ✅ Done in Taiga-family Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 This issue has low priority
Development

No branches or pull requests

8 participants