Skip to content
This repository has been archived by the owner on Sep 6, 2018. It is now read-only.

Commit

Permalink
fix regression with static methods
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed Mar 1, 2018
1 parent 5948edd commit 8dc7321
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "snekfetch",
"version": "4.0.0-rc.0",
"version": "4.0.0-beta.0",
"main": "src/index",
"module": "src/index.mjs",
"unpkg": "browser.js",
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class Snekfetch extends transport.Parent {
Snekfetch.METHODS = transport.METHODS.filter((m) => m !== 'M-SEARCH');
for (const method of Snekfetch.METHODS) {
Snekfetch[method.toLowerCase()] = function runMethod(url, opts) {
const Constructor = this.prototype instanceof Snekfetch ? this : Snekfetch;
const Constructor = this && this.prototype instanceof Snekfetch ? this : Snekfetch;
return new Constructor(method, url, opts);
};
}
Expand Down
10 changes: 8 additions & 2 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ function makeTestObj({ unicode = true, numbers = false } = {}) {
}

test('should return a promise', () => {
expect(Snekfetch.get(`${TestRoot}/get`).end())
.toBeInstanceOf(Promise);
for (const C of [
Snekfetch.get(`${TestRoot}/get`).end(),
Snekfetch.get.call(null, `${TestRoot}/get`).end(),
Snekfetch.get.call({}, `${TestRoot}/get`).end(),
]) {
expect(C)
.toBeInstanceOf(Promise);
}
});

test('should reject with error on network failure', () => {
Expand Down

0 comments on commit 8dc7321

Please sign in to comment.