我尝试使用 nock 和其他库(如 sinonjs)模拟 HTTP 请求,但没有成功。
import nock from "nock"
const URL = "http://localhost:8080/"
const SIGN_IN_PATH = "/fake/users/sign_in.json"
export const signInRequest = (status, payload = {}) => {
return nock(URL).get(SIGN_IN_PATH).reply(status, payload)
}
-
import { signInRequest } from "./../../utils/fakeRequests"
const doLogin = (browser) => {
return browser
.url("http://localhost:8080")
.waitForElementVisible('form', 1000)
.setValue('input[name=email]', 'foo@foo.com')
.setValue('input[name=password]', 'somepass')
.click('button[type=submit]')
.pause(500)
}
export default {
"Do login and shows error message": (browser) => {
signInRequest(403)
doLogin(browser)
.waitForElementVisible('.error', 1000)
.end()
}
}
夜班可能的模拟 http 请求?