Comments (5)
In order to resolve this, I had to add the following to any test file that indirectly imports abort-controller:
For example, in fetch.js:
import AbortController from "abort-controller"
Then, in test/fetch.spec.js
import { func1, func2, ... } from "../fetch"
jest.mock("event-target-shim", () => ({
EventTarget: () => "EventTarget",
defineEventAttribute: () => "defineEventAttribute"
}))
jest.mock(
"abort-controller",
() =>
class AbortController {
abort() {}
}
)
Do you think this warrants a mod to the README file? I can submit a PR if you are too busy.
from abort-controller.
Thank you for the investigation, and I'm sorry for my delay.
I'm not familiar with jest, but I feel odd if we have to know all indirect dependencies to use mocks because mocks should replace implementation and such indirect dependencies are the detail of implementation that should be replaced.
Does jest really require the knowledge of implementation details to use mocks? If yes, I can't add any new dependencies into this package since it will break jest's code even if it doesn't change any public API. It's a too strong restriction.
from abort-controller.
Toru, I don't know how to write tests for logic that makes asynchronous requests (HTTP) without writing mocks. I just didn't expect to have to write a mock for abort-controller and event-target-shim.
The problems appears to be that the node.js interpreter detects a circular reference when loading abort-controller.js and throws a run-time error.
There is no problem when the browser loads abort-controller. By that time, all libraries have been transpiled into ES5 and bundled by Webpack.
You might want to consider using babel to transpile the .js files in both libraries into ES5 for the dist/ directory for maximum compatibility.
from abort-controller.
Toru, I don't know how to write tests for logic that makes asynchronous requests (HTTP) without writing mocks. I just didn't expect to have to write a mock for abort-controller and event-target-shim.
I don't say "don't use mocks", but I suspect that jest's mock system has a critical defect that messes library to replace indirect dependencies with undefined.
The problems appears to be that the node.js interpreter detects a circular reference when loading abort-controller.js and throws a run-time error.
No. Any circular references don't exist in this library. The event-target-shim
doesn't have any dependencies. I think that Jest hacks and overwrites Node.js's module loading behavior and it messes require("event-target-shim")
of this library. Mock libraries need such hacks. But sane mocks would not replace internal dependencies with undefined silently.
You might want to consider using babel to transpile the .js files in both libraries into ES5 for the dist/ directory for maximum compatibility.
I don't think that I want to inflate the source code as unnecessary.
I'm laerning toward adding a note "minor/patch releases in future can break your Jest's tests because of the mock system."
from abort-controller.
from abort-controller.
Related Issues (20)
- Change `ev` parameter to `Event` once TS3.4 comes out HOT 2
- not working in IE 11 because the dist files are not transpiled to ES5 HOT 5
- TypeScript support is broken HOT 1
- ES-check error HOT 3
- umdOutro causes issues with webpack+babel HOT 1
- Add extension to package.json:main HOT 1
- AbortController as part of Node.js core
- Use native AbortController when possible. HOT 1
- can't ever reset a signal once it's been aborted HOT 2
- ie is not supported for this. how could we handle this problem ? HOT 1
- Update the event-target-shim dependency
- Unable to timeout Promise.
- Browser code missing named AbortController export
- Support for AbortSignal.reason HOT 1
- Add a ponyfill export
- Support for `AbortSignal.timeout` HOT 1
- TypeScript error: "Type 'AbortSignal' is missing the following properties from type 'AbortSignal': reason, throwIfAborted" HOT 5
- controller.signal.constructor.name is invalid? HOT 3
- ModuleNotFoundError on export HOT 1
- Broken on node 18.14.2 and 19.16.1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from abort-controller.