From b50ee760209561580014351a79dbdf23b1bd0716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Sat, 29 Sep 2018 20:33:20 +0200 Subject: [PATCH 1/6] version update --- CHANGELOG.md | 3 +++ package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a062747..4ac36d9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +1.3.0 / ####-##-## +================== + 1.2.0 / 2018-09-29 ================== diff --git a/package.json b/package.json index 3011a551..6389ec8b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wendigo", - "version": "1.2.0", + "version": "1.3.0", "description": "A proper monster for front-end automated testing", "engines": { "node": ">=8.0.0" From fa72a443a97e53f442d967c62feb9eee1c7412e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Sun, 30 Sep 2018 13:46:20 +0200 Subject: [PATCH 2/6] WIP tests on #204 --- tests/browser/timezone.test.js | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/browser/timezone.test.js diff --git a/tests/browser/timezone.test.js b/tests/browser/timezone.test.js new file mode 100644 index 00000000..0f51bc5a --- /dev/null +++ b/tests/browser/timezone.test.js @@ -0,0 +1,43 @@ +"use strict"; + +const assert = require('assert'); +const Wendigo = require('../../lib/wendigo'); +const configUrls = require('../config.json').urls; + + +// Skipped until #204 fixed +describe.skip("Timezone", function() { + this.timeout(5000); + let browser; + + function getTimezone() { + return browser.evaluate(() => { + return Intl.DateTimeFormat().resolvedOptions().timeZone; // eslint-disable-line new-cap + }); + } + + after(async() => { + await browser.close(); + }); + + it("Change Timezone To UTC", async() => { + browser = await Wendigo.createBrowser({ + timezone: "UTC" + }); + + await browser.open(configUrls.simple); + const tz = await getTimezone(); + assert.strictEqual(tz, "UTC"); + }); + + it("Change Timezone To Japan", async() => { + browser = await Wendigo.createBrowser({ + timezone: "Japan" + }); + await browser.open(configUrls.simple, { + timezone: "Japan" + }); + const tz = await getTimezone(); + assert.strictEqual(tz, "Japan"); + }); +}); From f13cf2eb58c86005fdb44ea81202bded051309ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Sun, 30 Sep 2018 17:17:46 +0200 Subject: [PATCH 3/6] waitforrequest and response changed, added waitfornextrequest and response, close #196 --- CHANGELOG.md | 3 ++ README.md | 16 +++++-- lib/mixins/browser_wait.js | 31 +++++++++++- lib/utils.js | 17 +++++++ tests/browser/wait_for_request.test.js | 66 ++++++++++++++++++++++++++ 5 files changed, 127 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ac36d9b..46d84265 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ 1.3.0 / ####-##-## ================== + * WaitForRequest and waitForResponse will resolve if the request was already made. + * WaitForNextRequest and waitForNextResponse added with the past behavior of waitForRequest/Response + 1.2.0 / 2018-09-29 ================== diff --git a/README.md b/README.md index 32f28806..6adf0e48 100644 --- a/README.md +++ b/README.md @@ -310,16 +310,22 @@ await browser.click("a"); await browser.waitForUrl("my-url"); ``` - **waitForRequest(url, timeout=500)** -Waits until a request with given url is done. +Waits until a request with given url is done. This will resolve immediately if the requests was already made, to wait without taking in account past requests use `waitForNextRequest`. ```js await browser.waitForRequest("my-url"); ``` **waitForResponse(url, timeout=500)** -Waits until a response to the given url is done. +Waits until a response to the given url is done. This will resolve immediately if the response was already received, to wait without taking in account past requests use `waitForNextResponse`. + +**waitForNextRequest(url ,timeout=500)** +Waits until next request with given url is done. If the request was already made, this method will wait until next one. + +**waitForNextResponse(url ,timeout=500)** +Waits until next response with given url is received. If the response was already received, this method will wait until next one. + **findByText(selector?, text)** Returns an array with the elements with text content matching the given text. @@ -1089,13 +1095,13 @@ await browser.filter.url(/api/).method("DELETE").body({id: 5}).requests; ``` **responseBody(expected)** -Filters requests by response body, the body can be a String, Object or regex. This filter returns a promise, so either then or await is required. Also it cannot be concatenated directly. +Filters requests by response body, the body can be a String, Object or regex. ```js const byResponseFilter = await browser.requests.filter.url(/api/).responseBody({response: 'OK'}).requests; ``` -> Keep in mind that some filters like status require the requests to be finished. Use `await browser.wait()` before filtering to make sure the requests was completed. +> Keep in mind that some filters like status require the requests to be finished. Use `await browser.waitForResponse()` before filtering to make sure the requests was completed. ### Requests Assertions Assertions related requests can be accessed through `browser.assert.request`. Note that in assertions, request is singular. diff --git a/lib/mixins/browser_wait.js b/lib/mixins/browser_wait.js index 0a4e2adf..612dc7a9 100644 --- a/lib/mixins/browser_wait.js +++ b/lib/mixins/browser_wait.js @@ -42,6 +42,35 @@ module.exports = function BrowserWaitMixin(s) { } waitForRequest(url, timeout = 500) { + const waitForPromise = this.waitForNextRequest(url, timeout); + + const alreadyRequestsPromise = this.requests.filter.url(url).requests.then((requests) => { + if (requests.length > 0) return Promise.resolve(); + else return Promise.reject(); + }); + + return utils.promiseOr([alreadyRequestsPromise, waitForPromise]).catch(() => { + return Promise.reject(new TimeoutError(`Waiting for request "${url}"`, timeout)); + }); + } + + waitForResponse(url, timeout = 500) { + const waitForPromise = this.waitForNextResponse(url, timeout); + + const alreadyResponsePromise = this.requests.filter.url(url).requests.then((requests) => { + const responded = requests.filter((request) => { + return Boolean(request.response()); + }); + if (responded.length > 0) return Promise.resolve(); + else return Promise.reject(); + }); + + return utils.promiseOr([alreadyResponsePromise, waitForPromise]).catch(() => { + return Promise.reject(new TimeoutError(`Waiting for response "${url}"`, timeout)); + }); + } + + waitForNextRequest(url, timeout = 500) { return this.page.waitForRequest(url, { timeout: timeout }).catch(() => { @@ -49,7 +78,7 @@ module.exports = function BrowserWaitMixin(s) { }); } - waitForResponse(url, timeout = 500) { + waitForNextResponse(url, timeout = 500) { return this.page.waitForResponse(url, { timeout: timeout }).catch(() => { diff --git a/lib/utils.js b/lib/utils.js index 6b0f222a..3feb9b1b 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -17,6 +17,23 @@ module.exports = { return promise.then(result => func().then(Array.prototype.concat.bind(result))); }, Promise.resolve([])); }, + promiseOr(promises) { // Returns promise resolve if any promise is resolved, reject otherwise + let resolved = false; + let rejected = 0; + return new Promise((resolve, reject) => { + for (const promise of promises) { + promise.then((res) => { + if (!resolved) { + resolved = true; + resolve(res); + } + }).catch(() => { + rejected++; + if (!resolved && rejected >= promises.length) reject(); + }); + } + }); + }, matchText(text, expected) { if (expected instanceof RegExp) { return expected.test(text); diff --git a/tests/browser/wait_for_request.test.js b/tests/browser/wait_for_request.test.js index 4bc9cae7..94d635f0 100644 --- a/tests/browser/wait_for_request.test.js +++ b/tests/browser/wait_for_request.test.js @@ -31,6 +31,14 @@ describe("Wait For Request", function() { await browser.assert.request.url(/api/); }); + it("Wait For Request Already Made", async() => { + await browser.clickText("click me"); + await browser.wait(10); + await browser.assert.request.url(/api/).exactly(1); + await browser.waitForRequest("http://localhost:3456/api"); + await browser.assert.request.url(/api/).exactly(1); + }); + it("Wait For Request With Mock", async() => { await browser.requests.mock("http://localhost:3456/api"); setTimeout(() => { @@ -54,6 +62,18 @@ describe("Wait For Request", function() { await browser.assert.request.url(/api/).responseBody("test"); }); + it("Wait For Response Already Made", async() => { + await browser.requests.mock("http://localhost:3456/api", { + body: "test" + }); + await browser.clickText("click me"); + await browser.wait(10); + await browser.assert.request.url(/api/).exactly(1); + await browser.assert.request.url(/api/).responseBody("test").exactly(1); + await browser.waitForResponse("http://localhost:3456/api"); + await browser.assert.request.url(/api/).responseBody("test").exactly(1); + }); + it("Wait For Request Timeout", async() => { await utils.assertThrowsAsync(async() => { await browser.waitForRequest("http://localhost:3456/api", 10); @@ -65,4 +85,50 @@ describe("Wait For Request", function() { await browser.waitForResponse("http://localhost:3456/api", 10); }, `TimeoutError: Waiting for response "http://localhost:3456/api", timeout of 10ms exceeded.`); }); + + + it("Wait For Next Request", async() => { + setTimeout(() => { + browser.clickText("click me"); + }, 100); + await browser.assert.request.url(/api/).exactly(0); + await browser.waitForNextRequest("http://localhost:3456/api"); + await browser.assert.request.url(/api/); + }); + + it("Wait For Next Request Already Made", async() => { + await browser.clickText("click me"); + await browser.wait(10); + await browser.assert.request.url(/api/).exactly(1); + await utils.assertThrowsAsync(async() => { + await browser.waitForNextRequest("http://localhost:3456/api", 10); + }, `TimeoutError: Waiting for request "http://localhost:3456/api", timeout of 10ms exceeded.`); + }); + + it("Wait For Next Response With Mock", async() => { + await browser.requests.mock("http://localhost:3456/api", { + delay: 500, + body: "test" + }); + await browser.clickText("click me"); + await browser.wait(10); + await browser.assert.request.url(/api/).exactly(1); + await browser.assert.request.url(/api/).responseBody("test").exactly(0); + await browser.waitForNextResponse("http://localhost:3456/api"); + await browser.assert.request.url(/api/).responseBody("test"); + }); + + it("Wait For Next Response Already Made", async() => { + await browser.requests.mock("http://localhost:3456/api", { + body: "test" + }); + await browser.clickText("click me"); + await browser.wait(10); + await browser.assert.request.url(/api/).exactly(1); + await browser.assert.request.url(/api/).responseBody("test").exactly(1); + await utils.assertThrowsAsync(async() => { + await browser.waitForNextResponse("http://localhost:3456/api", 10); + }, `TimeoutError: Waiting for response "http://localhost:3456/api", timeout of 10ms exceeded.`); + await browser.assert.request.url(/api/).responseBody("test").exactly(1); + }); }); From 85680ad63b4e265c2f134798b3860ce44258ef93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Sun, 30 Sep 2018 17:36:29 +0200 Subject: [PATCH 4/6] click on label test --- tests/browser/click.test.js | 6 ++++++ tests/dummy_server/static/forms.html | 20 ++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/tests/browser/click.test.js b/tests/browser/click.test.js index 6d754827..9cdbf7c9 100644 --- a/tests/browser/click.test.js +++ b/tests/browser/click.test.js @@ -113,4 +113,10 @@ describe("Click", function() { const clickedElements = await browser.clickText("body", "click me delay", 0); assert.strictEqual(clickedElements, 1); }); + + it("Click Label", async() => { + await browser.open(configUrls.forms); + await browser.click("label"); + await browser.assert.text("#value-input", "Label"); + }); }); diff --git a/tests/dummy_server/static/forms.html b/tests/dummy_server/static/forms.html index 39a93300..b0f60795 100644 --- a/tests/dummy_server/static/forms.html +++ b/tests/dummy_server/static/forms.html @@ -4,23 +4,24 @@

Main Title

+ First Input: Last Input:

@@ -32,6 +33,9 @@

Main Title

document.querySelector(".input1").onkeypress = function(ev) { document.getElementById("value-input").textContent = String.fromCharCode(ev.charCode) }; + document.querySelector(".label1").onclick = function(ev) { + document.getElementById("value-input").textContent = "Label" + }; From 9d8a35476f591cee80ba5260feb07765bcb104f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Mon, 1 Oct 2018 15:57:52 +0200 Subject: [PATCH 5/6] mock.waitUntilCalled, close #197 --- CHANGELOG.md | 1 + README.md | 1 + lib/models/request_mock.js | 22 ++- lib/modules/browser_requests.js | 1 + lib/request_mocker.js | 6 +- .../request_mock_object.test.js | 140 ++++++++++++++++++ .../browser_components/request_mocker.test.js | 91 ------------ 7 files changed, 164 insertions(+), 98 deletions(-) create mode 100644 tests/browser_components/request_mock_object.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 46d84265..b1a42c3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * WaitForRequest and waitForResponse will resolve if the request was already made. * WaitForNextRequest and waitForNextResponse added with the past behavior of waitForRequest/Response + * Mock WaitUntilCalled method 1.2.0 / 2018-09-29 ================== diff --git a/README.md b/README.md index 6adf0e48..3a19fcd9 100644 --- a/README.md +++ b/README.md @@ -1002,6 +1002,7 @@ Mock will return a RequestMock object, with the following properties: * `queryString`: The mock queryString * `immediate`: If the mock will return immediately (delay=0) * `assert.called(times?)`: asserts that the mock has been called the given number of times, if times parameter is not given, the assertion will throw if no calls were made +* `waitUntilCalled(timeout=500)`: Waits until the mock is called * `auto`: If the request will be completed automatically ```js diff --git a/lib/models/request_mock.js b/lib/models/request_mock.js index 425f5c6f..1c987d26 100644 --- a/lib/models/request_mock.js +++ b/lib/models/request_mock.js @@ -3,7 +3,7 @@ const EventEmitter = require('events'); const URL = require('url').URL; -const {FatalError, AssertionError} = require('../errors'); +const {FatalError, AssertionError, TimeoutError} = require('../errors'); const utils = require('../utils'); @@ -59,8 +59,26 @@ module.exports = class RequestMock { this._events.emit("respond"); } - increaseCalled() { + waitUntilCalled(timeout = 500) { + if (this.called) return Promise.resolve(); + return new Promise((resolve, reject) => { + let rejected = false; + const tid = setTimeout(() => { + rejected = true; + reject(new TimeoutError(`Wait until mock of "${this.url}" is called`, timeout)); + }, timeout); + this._events.once("on-request", () => { + if (!rejected) { + clearTimeout(tid); + resolve(); + } + }); + }); + } + + onRequest() { this._timesCalled++; + this._events.emit("on-request"); } _assertCalled(times, msg) { diff --git a/lib/modules/browser_requests.js b/lib/modules/browser_requests.js index cbe7c27f..f0f3d629 100644 --- a/lib/modules/browser_requests.js +++ b/lib/modules/browser_requests.js @@ -51,6 +51,7 @@ module.exports = class BrowserRequests extends BrowserModule { } _respondWithMock(request, mock) { + mock.onRequest(); if (mock.auto && mock.immediate) { return request.respond(mock.response); } else if (mock.auto) { diff --git a/lib/request_mocker.js b/lib/request_mocker.js index 4baf7c5a..b90a7499 100644 --- a/lib/request_mocker.js +++ b/lib/request_mocker.js @@ -13,14 +13,10 @@ module.exports = class RequestMocker { getMockedResponse(request) { const url = new URL(request.url()); const method = request.method(); - const mock = this._getMock(`${url.origin}${url.pathname}`, { + return this._getMock(`${url.origin}${url.pathname}`, { method: method, queryString: url.search ? utils.parseQueryString(url) : undefined }); - if (mock) { // TODO: move this to request ? - mock.increaseCalled(); - return mock; - } } mockRequest(url, options) { diff --git a/tests/browser_components/request_mock_object.test.js b/tests/browser_components/request_mock_object.test.js new file mode 100644 index 00000000..f9df27e8 --- /dev/null +++ b/tests/browser_components/request_mock_object.test.js @@ -0,0 +1,140 @@ +"use strict"; + +const assert = require('assert'); +const Wendigo = require('../../lib/wendigo'); +const configUrls = require('../config.json').urls; +const utils = require('../test_utils'); + +describe("Requests Mock Object", function() { + this.timeout(5000); + let browser; + const mockResponse = { + body: {result: "MOCK"} + }; + + beforeEach(async() => { + browser = await Wendigo.createBrowser(); + await browser.open(configUrls.requests); + }); + + afterEach(async() => { + await browser.close(); + }); + + it("Mocker Object", async() => { + const mock = browser.requests.mock(configUrls.api, mockResponse); + assert.strictEqual(mock.called, false); + await browser.clickText("click me"); + await browser.wait(100); + await browser.assert.text("#result", "MOCK"); + assert.strictEqual(mock.called, true); + assert.strictEqual(mock.auto, true); + }); + + it("Mocker Object timesCalled", async() => { + const mock = browser.requests.mock(configUrls.api, mockResponse); + assert.strictEqual(mock.timesCalled, 0); + await browser.clickText("click me"); + await browser.clickText("click me"); + await browser.wait(100); + await browser.assert.text("#result", "MOCK"); + assert.strictEqual(mock.timesCalled, 2); + }); + + it("Mocker Object Assertion", async() => { + const mock = browser.requests.mock(configUrls.api, mockResponse); + assert.strictEqual(mock.called, false); + await browser.clickText("click me"); + await browser.wait(100); + mock.assert.called(); + }); + + it("Mocker Object Assertion Throws", async() => { + const mock = browser.requests.mock(configUrls.api, mockResponse); + await utils.assertThrowsAssertionAsync(async() => { + await mock.assert.called(); + }, `Mock of ${configUrls.api} not called.`); + }); + + it("Mocker Object Assertion Throws With Message", async() => { + const mock = browser.requests.mock(configUrls.api, mockResponse); + await utils.assertThrowsAssertionAsync(async() => { + await mock.assert.called(undefined, "called throws"); + }, `called throws`); + }); + + it("Mocker Object Assertion Times", async() => { + const mock = browser.requests.mock(configUrls.api, mockResponse); + mock.assert.called(0); + await browser.clickText("click me"); + await browser.wait(100); + mock.assert.called(1); + await browser.clickText("click me"); + await browser.wait(100); + mock.assert.called(2); + }); + + it("Mocker Object Assertion Times Throws", async() => { + const mock = browser.requests.mock(configUrls.api, mockResponse); + await browser.clickText("click me"); + await browser.wait(100); + + await utils.assertThrowsAssertionAsync(async() => { + await mock.assert.called(2); + }, `Mock of ${configUrls.api} not called 2 times.`); + }); + + it("Mocker Object Assertion Times Throws", async() => { + const mock = browser.requests.mock(configUrls.api, mockResponse); + assert.strictEqual(mock.immediate, true); + await utils.assertThrowsAssertionAsync(async() => { + await mock.assert.called(2, "called fails"); + }, `called fails`); + }); + + it("Mock With Trigger", async() => { + const response = Object.assign({ + auto: false + }, mockResponse); + const mock = browser.requests.mock(configUrls.api, response); + assert.strictEqual(mock.auto, false); + await browser.clickText("click me"); + await browser.assert.not.text("#result", "MOCK"); + mock.trigger(); + await browser.assert.text("#result", "MOCK"); + }); + + it("Auto Mock With Trigger", async() => { + const mock = browser.requests.mock(configUrls.api, mockResponse); + await utils.assertThrowsAsync(async() => { + await mock.trigger(); + }, `FatalError: Cannot trigger auto request mock.`); + }); + + it("Wait Until Mock Called", async() => { + const mock = browser.requests.mock(configUrls.api, mockResponse); + setTimeout(() => { + browser.clickText("click me"); + }, 300); + await browser.assert.not.text("#result", "MOCK"); + await mock.waitUntilCalled(); + await browser.assert.text("#result", "MOCK"); + }); + + it("Wait After Mock Called", async() => { + const mock = browser.requests.mock(configUrls.api, mockResponse); + await browser.clickText("click me"); + await browser.wait(10); + await browser.assert.text("#result", "MOCK"); + await mock.waitUntilCalled(); + await browser.assert.text("#result", "MOCK"); + }); + + it("Wait Until Mock Called Timeout", async() => { + const mock = browser.requests.mock(configUrls.api, mockResponse); + await browser.assert.not.text("#result", "MOCK"); + await utils.assertThrowsAsync(async() => { + await mock.waitUntilCalled(10); + }, `TimeoutError: Wait until mock of "${configUrls.api}" is called, timeout of 10ms exceeded.`); + }); +}); diff --git a/tests/browser_components/request_mocker.test.js b/tests/browser_components/request_mocker.test.js index 0e3ab0b3..3ec96ec8 100644 --- a/tests/browser_components/request_mocker.test.js +++ b/tests/browser_components/request_mocker.test.js @@ -3,7 +3,6 @@ const assert = require('assert'); const Wendigo = require('../../lib/wendigo'); const configUrls = require('../config.json').urls; -const utils = require('../test_utils'); describe("Requests Mocker", function() { this.timeout(5000); @@ -12,7 +11,6 @@ describe("Requests Mocker", function() { body: {result: "MOCK"} }; - beforeEach(async() => { browser = await Wendigo.createBrowser(); await browser.open(configUrls.requests); @@ -140,77 +138,6 @@ describe("Requests Mocker", function() { await browser.assert.text("#result", "MOCK"); }); - it("Mocker Object", async() => { - const mock = browser.requests.mock(configUrls.api, mockResponse); - assert.strictEqual(mock.called, false); - await browser.clickText("click me"); - await browser.wait(100); - await browser.assert.text("#result", "MOCK"); - assert.strictEqual(mock.called, true); - assert.strictEqual(mock.auto, true); - }); - - it("Mocker Object timesCalled", async() => { - const mock = browser.requests.mock(configUrls.api, mockResponse); - assert.strictEqual(mock.timesCalled, 0); - await browser.clickText("click me"); - await browser.clickText("click me"); - await browser.wait(100); - await browser.assert.text("#result", "MOCK"); - assert.strictEqual(mock.timesCalled, 2); - }); - - it("Mocker Object Assertion", async() => { - const mock = browser.requests.mock(configUrls.api, mockResponse); - assert.strictEqual(mock.called, false); - await browser.clickText("click me"); - await browser.wait(100); - mock.assert.called(); - }); - - it("Mocker Object Assertion Throws", async() => { - const mock = browser.requests.mock(configUrls.api, mockResponse); - await utils.assertThrowsAssertionAsync(async() => { - await mock.assert.called(); - }, `Mock of ${configUrls.api} not called.`); - }); - - it("Mocker Object Assertion Throws With Message", async() => { - const mock = browser.requests.mock(configUrls.api, mockResponse); - await utils.assertThrowsAssertionAsync(async() => { - await mock.assert.called(undefined, "called throws"); - }, `called throws`); - }); - - it("Mocker Object Assertion Times", async() => { - const mock = browser.requests.mock(configUrls.api, mockResponse); - mock.assert.called(0); - await browser.clickText("click me"); - await browser.wait(100); - mock.assert.called(1); - await browser.clickText("click me"); - await browser.wait(100); - mock.assert.called(2); - }); - - it("Mocker Object Assertion Times Throws", async() => { - const mock = browser.requests.mock(configUrls.api, mockResponse); - await browser.clickText("click me"); - await browser.wait(100); - - await utils.assertThrowsAssertionAsync(async() => { - await mock.assert.called(2); - }, `Mock of ${configUrls.api} not called 2 times.`); - }); - - it("Mocker Object Assertion Times Throws", async() => { - const mock = browser.requests.mock(configUrls.api, mockResponse); - assert.strictEqual(mock.immediate, true); - await utils.assertThrowsAssertionAsync(async() => { - await mock.assert.called(2, "called fails"); - }, `called fails`); - }); - it("Keep Mocks On Open", async() => { browser.requests.mock(configUrls.api, mockResponse); await browser.open(configUrls.requests, {clearRequestMocks: false}); @@ -238,24 +165,6 @@ describe("Requests Mocker", function() { await browser.assert.text("#result", "MOCK"); }); - it("Mock With Trigger", async() => { - const response = Object.assign({ - auto: false - }, mockResponse); - const mock = browser.requests.mock(configUrls.api, response); - assert.strictEqual(mock.auto, false); - await browser.clickText("click me"); - await browser.assert.not.text("#result", "MOCK"); - mock.trigger(); - await browser.assert.text("#result", "MOCK"); - }); - - it("Auto Mock With Trigger", async() => { - const mock = browser.requests.mock(configUrls.api, mockResponse); - await utils.assertThrowsAsync(async() => { - await mock.trigger(); - }, `FatalError: Cannot trigger auto request mock.`); - }); it("Mock With QueryString", async() => { browser.requests.mock(configUrls.api, mockResponse); From 2f9e6ce7fc14e80f7ecf57e42e1267e92f318b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Mon, 1 Oct 2018 16:00:57 +0200 Subject: [PATCH 6/6] 1.3.0 --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1a42c3d..194575a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ -1.3.0 / ####-##-## +1.3.0 / 2018-10-01 ================== - * WaitForRequest and waitForResponse will resolve if the request was already made. + * WaitForRequest and waitForResponse will resolve if the request was already made * WaitForNextRequest and waitForNextResponse added with the past behavior of waitForRequest/Response * Mock WaitUntilCalled method