Problem · Resolved

Angular 15 Unit Testing Not Working

AOAnonymous One· Feb 12, 20231 min read
  • #Angular
  • #Unit Test

Angular 15 Unit Testing Not Working

Getting an error typically thrown when there's an issue with webpack or one of its plugins.

Problem:

Try to run a unit test ng test

Error message: 

Uncaught TypeError: __webpack_require__(...).context is not a function

Resolution

Edit angular.json test project

Change from

"test": {
          ...
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            ...
            ...
          }
        },

To

"test": {
          ...
          "options": {
            "polyfills": ["zone.js", "zone.js/testing"],
            "tsConfig": "tsconfig.spec.json",
            ...
            ...
          }
        },

0 Comments

Sign in to join the conversation.

Search

Jump to a page, story or project