Skip to content

Commit 1d751f4

Browse files
authored
fix regression introduced in v3.6.0 with string urls (#62)
* fix regression introduced in v3.6.0 with string urls * Avoid a useless Object.assign()
1 parent 41e0bd6 commit 1d751f4

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ function doInject (dispatchFunc, options, callback) {
100100
}
101101

102102
function Chain (dispatch, option) {
103-
this.option = Object.assign({}, option)
103+
if (typeof option === 'string') {
104+
this.option = { url: option }
105+
} else {
106+
this.option = Object.assign({}, option)
107+
}
108+
104109
this.dispatch = dispatch
105110
this._hasInvoked = false
106111
this._promise = null

test/test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,20 @@ test('chainable api: invoking end method multiple times should throw', (t) => {
11981198
t.throws(() => chain.end(), Error)
11991199
})
12001200

1201+
test('chainable api: string url', (t) => {
1202+
t.plan(2)
1203+
1204+
function dispatch (req, res) {
1205+
res.writeHead(200, { 'Content-Type': 'text/plain' })
1206+
res.end()
1207+
t.pass()
1208+
}
1209+
1210+
const chain = inject(dispatch, 'http://example.com:8080/hello')
1211+
1212+
chain.then(() => t.pass())
1213+
})
1214+
12011215
test('Response.json() should parse the JSON payload', (t) => {
12021216
t.plan(2)
12031217

0 commit comments

Comments
 (0)