chaijs / chai-http

HTTP Response assertions for the Chai Assertion Library.
http://chaijs.com/plugins/chai-http
633 stars 113 forks source link

Rework to using classes instead of prototypes #318

Open 43081j opened 7 months ago

43081j commented 7 months ago

In much of this library, we use functions as constructors and add methods to the prototype, using util.inherits for inheritance

We should probably rework this to use classes now that they're widely available.

For example: https://github.com/chaijs/chai-http/blob/cc58a4b67920b70131969ffa450f53810a2c92dd/lib/request.js#L307-L318

Could be:

class TestAgent extends (Agent || Request) {
  constructor(app) {
    super();
    if (typeof app === 'function') app = http.createServer(app);
    this.app = app;
    if (typeof app !== 'string' && app && app.listen && app.address && !app.address()) {
      this.app = app.listen(0)
    }
  }

  close(callback) {
    // ...
  }
}