From 193b3eb90db3f03de45e7c599e40f018a64bc213 Mon Sep 17 00:00:00 2001 From: bobenut <33755383@qq.com> Date: Wed, 14 Mar 2018 20:26:35 +0800 Subject: [PATCH] add ok prop for response --- src/index.js | 1 + src/response.js | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/index.js b/src/index.js index ad88a26..d84d887 100644 --- a/src/index.js +++ b/src/index.js @@ -135,6 +135,7 @@ class FetchMock { obj = { status: 200, data: obj, + ok: true }; } diff --git a/src/response.js b/src/response.js index 85123b1..cc5e8fc 100644 --- a/src/response.js +++ b/src/response.js @@ -22,6 +22,14 @@ class Response { return this[_statusText]; } + get ok() { + if (this[_status] >= 200 && this[_status] < 300) { + return true; + } else { + return false; + } + } + text() { try { return Promise.resolve(JSON.stringify(this[_data]));