question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using jest-preset-angular with Pact for Contract Testing

See original GitHub issue

Hello I’m trying to configure a Consumer based contract test using Pact library which requires Jest to run in a Node test environment.

Receiving this error when I try to run my test. ReferenceError: XMLHttpRequest is not defined I see that jest-preset-angular brings in zone.js which is trying to pull in xhr.

Any way around this? Thank you for your time.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:9

github_iconTop GitHub Comments

1reaction
wthocommented, Jan 11, 2020

@39ro actually we override testEnvironment when you load jest-preset-angular to use the latest jsdom as test environment: https://github.com/thymikee/jest-preset-angular/blob/c05c122ec4e364d3a59b8524478b9425feadd059/jest-preset.js#L15

Anyway the XMLHttpRequest error is usually related to the preset not being loaded properly or global.ts-jest options overwritten in a wrong way, not as described in the README.md. If the ts-jest ast transformers are loaded properly, XMLHttpRequests are not required anymore.

0reactions
ahnpnlcommented, Apr 30, 2021

Close as inactivity

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set up Pact tests with Angular & Jest | by Dany Marques
Let's first create an Angular service using Angular schematics. This will create a user service under core folder. ... You're now able to...
Read more >
API contract testing with Pact and Angular - Stack Overflow
I can't quite see what's happening with the proxy, but it doesn't seem to align with what your code actually does (the proxy...
Read more >
jest-pact - npm
Start using jest-pact in your project by running `npm i jest-pact`. There is 1 other project in the npm registry using jest-pact.
Read more >
Consumer Driven Contract Testing with Pact - Blog - RisingStack
To test the contract, we need to set up the pact verifier first. We'll be using [pact-node](https://github.com/pact-foundation/pact-node) for ...
Read more >
Introduction To Pact Contract Testing With Examples
Contract tests fit nicely within a microservice architecture, operating in an agile setting. Therefore examples will be based on the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found