Angular 13 & Jest 27 & GoJS 2.2 unit test errors

Hi all,

We are using version 2.1.56 along with Angular 13.2 and Jest 27. All angular-dependent packages are up to date and working fine.

I tried to update gojs also to the latest version (2.2.3) and lots of unit tests began to fail due to the useDOM function and other functions too. We have a beforeAll hook making lots of unit test to fail

beforeAll(() => go.Diagram.useDOM(false));

Errors are like these:

TypeError: go.Diagram.useDOM is not a function

...

TypeError: a.getContext is not a function
    > 6 |   $(go.Diagram, {
        |   ^
      7 |     model: $(go.GraphLinksModel),
      8 |   });

Why v2.1 is compatible with Angular 13 and v2.2 is failing while testing with jest 27? Anyone with the same issue?

Thanks

So for some reason the GoJS library isn’t being loaded? I cannot explain that.

There is a bug involving the Shadow DOM that we introduced in 2.2.0 and have fixed in 2.2.4, which hasn’t been released yet but is in beta at: GoJS Beta. Try using https://gojs.net/beta/release/go.js or go-module.js to see if things work for you. If so, we’ll release it very soon.

I replaced the go.js file under node_modules with the beta one and I have the same issue.

It’s easy to reproduce.

  1. Clone repo and open folder https://github.com/thymikee/jest-preset-angular/tree/main/examples/example-app-v13
  2. npm i
  3. npm i gojs
  4. Replace existing go.js and go.d.ts by the beta ones
  5. Open any spec file like /src/app/app.component.spec.ts
  6. Add this line under the describe:
    beforeAll(() => go.Diagram.useDOM(false));
    Also import the module: import * as go from 'gojs';
  7. execute spec file
  8. Errors appears:
    TypeError: go.Diagram.useDOM is not a function

      22 |
      23 | describe('AppComponent & TestModule', () => {
    > 24 |   beforeAll(() => go.Diagram.useDOM(false));

Did you first add an import statement to the file?

import * as go from "gojs";

Yes, sorry, forgot to mention.

Thanks for the instructions – we’ll look into it.

Sorry about this. Diagram static functions isUsingDOM and useDOM were failing minification. This has been fixed and will be out with the next release, probably some time today, once we test for similar issues.

We have just released GoJS 2.2.4, which should fix this issue.

Thanks! Tested and working.