Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/7' into feat/jest24
Browse files Browse the repository at this point in the history
* origin/release/7:
  feat: jsdom-v13 (#229)
  fix: moved @types/jest to devDependencies (#227)
  • Loading branch information
thymikee committed Mar 4, 2019
2 parents cc985bd + e531b43 commit 6b83174
Show file tree
Hide file tree
Showing 8 changed files with 1,062 additions and 57 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

* (**BREAKING**): Upgrade ts-jest to ^23.10.4 and use ast-transformer instead of processor ([#204](https://github.com/thymikee/jest-preset-angular/pull/204))
* Chore: Remove template literal character escaping (reverts [#34](https://github.com/thymikee/jest-preset-angular/pull/34))
* Feat: Use test environment JSDOM v13 by default ([#229](https://github.com/thymikee/jest-preset-angular/pull/229))


#### Migration Guide

Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,16 @@ global.$ = global.jQuery = $;
The same declaration can be applied to other vendor libraries.

Reference: https://github.com/facebook/jest/issues/708

### Failing with Node v7 or lower

By default we use JSDOM v13, which requires Node v8+. If you want to use Node in a lower version to run your tests, make sure to configure jest to use an older JSDOM version, either in your `jest.config.js`, `jest.config.json` or `package.json`:

```json
"testEnvironment": "jsdom"
```

If you use JSDOM v11 or lower, you might have to mock `localStorage` or `sessionStorage` on your own or using some third-party library by loading it in `setupFilesAfterEnv`.

Reference: https://jestjs.io/docs/en/configuration.html#testenvironment-string, https://github.com/jsdom/jsdom/blob/master/Changelog.md#1200

1 change: 1 addition & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@angular-devkit/build-angular": "^0.7.3",
"@angular/cli": "^6.1.3",
"@angular/compiler-cli": "6.1.2",
"@types/jest": "^23.3.14",
"@types/node": "^10.5.8",
"codelyzer": "^4.4.3",
"jest": "^24.0.0",
Expand Down
12 changes: 0 additions & 12 deletions example/src/jestGlobalMocks.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
const createStorageMock = () => {
let storage = {};
return {
getItem: key => key in storage ? storage[key] : null,
setItem: (key, value) => storage[key] = value || '',
removeItem: key => delete storage[key],
clear: () => storage = {},
};
};

Object.defineProperty(window, 'CSS', {value: null});
Object.defineProperty(window, 'localStorage', {value: createStorageMock()});
Object.defineProperty(window, 'sessionStorage', {value: createStorageMock()});
Object.defineProperty(document, 'doctype', {
value: '<!DOCTYPE html>'
});
Expand Down
Loading

0 comments on commit 6b83174

Please sign in to comment.