diff --git a/MIGRATION.MD b/MIGRATION.MD index aa724f6a7..0cef3bf34 100644 --- a/MIGRATION.MD +++ b/MIGRATION.MD @@ -8,6 +8,7 @@ 1. Jest 29 is required now, refer to its [CHANGELOG](https://github.com/kulshekhar/ts-jest/blob/main/CHANGELOG.md#2900-2022-09-08) for details. 2. `jest-preset-angular` has been updated to version 13. Make sure you understand the implications and perform all the necessary changes to your code base as described in `jest-preset-angular` [CHANGELOG](https://github.com/thymikee/jest-preset-angular/blob/main/CHANGELOG.md#1300-2023-02-18). +3. Global mocks for `getComputedStyle` and `doctype` are disabled by default, the `jsdom` implementation is used instead. The mocks are still available via the option `globalMocks`. # Migration from version 14 to version 15 diff --git a/examples/jest/simple-app/src/app/app.component.spec.ts b/examples/jest/simple-app/src/app/app.component.spec.ts index ccd0f7c8f..b6241ff97 100644 --- a/examples/jest/simple-app/src/app/app.component.spec.ts +++ b/examples/jest/simple-app/src/app/app.component.spec.ts @@ -3,16 +3,12 @@ import { AppComponent } from './app.component'; import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; describe('AppComponent', () => { - beforeEach( - waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [AppComponent], - schemas: [ - CUSTOM_ELEMENTS_SCHEMA - ] - }).compileComponents(); - }) - ); + beforeEach(waitForAsync(() => { + TestBed.configureTestingModule({ + declarations: [AppComponent], + schemas: [CUSTOM_ELEMENTS_SCHEMA], + }).compileComponents(); + })); it('should create the app', () => { const fixture = TestBed.createComponent(AppComponent); @@ -20,9 +16,7 @@ describe('AppComponent', () => { expect(app).toBeTruthy(); }); - it(`should have all the global mocks defined`, () => { - expect(window.getComputedStyle).toBeTruthy(); - expect(document.doctype as any).toEqual(''); + it(`should have all the default global mocks are defined`, () => { expect(window.matchMedia).toBeTruthy(); expect(document.body.style.transform).toBeTruthy(); }); diff --git a/packages/jest/README.md b/packages/jest/README.md index edaaf7fee..1da03cb2f 100644 --- a/packages/jest/README.md +++ b/packages/jest/README.md @@ -99,20 +99,20 @@ The builder supports multi-project workspaces out of the box, the only thing req Or, if you'd like the same custom configuration to be applied to all the projects in the workspace, you just specify it in _package.json_. Another option in such a case is creating a single config file in the workspace root and specifying it in _angular.json_ for each project. - `tsConfig` - path to tsconfig file. If the path is relative then it is evaluated relative to the _project root_. Defaults to `tsconfig.spec.json` that is located in _project root_. -- `globalMocks` - there are 4 global mocks enabled by default: +- `globalMocks` - there are 4 global mocks available: `["getComputedStyle", "doctype", "styleTransform", "matchMedia"]`. The mocks implementation can be found [here](./src/global-mocks). - `styleTransform` and `matchMedia` are not implemented in jsdom. + `styleTransform` and `matchMedia` are not implemented in jsdom, therefore these are enabled by default. + `getComputedStyle` and `doctype` are implemented but do not support 100% of cases. - In the next major release, we'll still provide global mocks for implemented jsdom functions but they won't be enabled by default. - If you want to disable one or more of these mocks just pass an updated array in options. + If you want to disable/enable one or more of these mocks just pass an updated list in options. For example: ```json "options": { - "globalMocks": ["styleTransform", "matchMedia"] + "globalMocks": ["styleTransform", "matchMedia", "getComputedStyle"] } ``` diff --git a/packages/jest/src/schema.json b/packages/jest/src/schema.json index 286c09f9d..f420f4ac6 100644 --- a/packages/jest/src/schema.json +++ b/packages/jest/src/schema.json @@ -14,7 +14,7 @@ "items": { "type": "string" }, - "default": ["getComputedStyle", "doctype", "styleTransform", "matchMedia"] + "default": ["styleTransform", "matchMedia"] }, "all": { "description": "The opposite of `onlyChanged`. If `onlyChanged` is set by default, running jest with `--all` will force Jest to run all tests instead of running only tests related to changed files."