Skip to content

Commit

Permalink
Request mock should handle only specified requests (part of DevExpres…
Browse files Browse the repository at this point in the history
  • Loading branch information
miherlosev authored and AndreyBelym committed Apr 24, 2018
1 parent d4be3b1 commit 3b13bc0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/api/request-hooks/request-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { RequestHookConfigureAPIError } from '../../errors/test-run/index';

class RequestMock extends RequestHook {
constructor () {
super();
super([]);

this.pendingRequestFilterRuleInit = null;
this.mocks = new Map();
Expand Down
77 changes: 44 additions & 33 deletions test/server/request-hooks-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,46 +183,57 @@ describe('RequestLogger', () => {
});
});

describe('RequestMock (throwing errors)', () => {
describe('Chaining', () => {
it('.respond().onRequestTo()', () => {
assertThrow(() => {
RequestMock().respond(noop).onRequestTo({});
}, {
isTestCafeError: true,
requestHookName: 'RequestMock',
errMsg: "The 'onRequestTo' method was not called before 'respond'. You must call the 'onRequestTo' method to provide the URL requests to which are mocked.",
type: 'requestHookConfigureAPIError',
callsite: null
describe('RequestMock', () => {
describe('Throwing errors', () => {
describe('Chaining', () => {
it('.respond().onRequestTo()', () => {
assertThrow(() => {
RequestMock().respond(noop).onRequestTo({});
}, {
isTestCafeError: true,
requestHookName: 'RequestMock',
errMsg: "The 'onRequestTo' method was not called before 'respond'. You must call the 'onRequestTo' method to provide the URL requests to which are mocked.",
type: 'requestHookConfigureAPIError',
callsite: null
});
});

it('onRequestTo().onRequestTo()', () => {
assertThrow(() => {
RequestMock().onRequestTo({}).onRequestTo({});
}, {
isTestCafeError: true,
requestHookName: 'RequestMock',
errMsg: "The 'respond' method was not called after 'onRequestTo'. You must call the 'respond' method to provide the mocked response.",
type: 'requestHookConfigureAPIError',
callsite: null
});
});
});

it('onRequestTo().onRequestTo()', () => {
assertThrow(() => {
RequestMock().onRequestTo({}).onRequestTo({});
}, {
isTestCafeError: true,
requestHookName: 'RequestMock',
errMsg: "The 'respond' method was not called after 'onRequestTo'. You must call the 'respond' method to provide the mocked response.",
type: 'requestHookConfigureAPIError',
callsite: null
describe('Construction', () => {
it('Without configure', () => {
expect(() => {
RequestMock();
}).to.not.throw;
});
it('With configure', () => {
expect(() => {
RequestMock()
.onRequestTo('http://example.com')
.respond('<html></html>');
}).to.not.throw;
});
});
});

describe('Construction', () => {
it('Without configure', () => {
expect(() => {
RequestMock();
}).to.not.throw;
});
it('With configure', () => {
expect(() => {
RequestMock()
.onRequestTo('http://example.com')
.respond('<html></html>');
}).to.not.throw;
});
it('Should handle only specified requests (GH-2336)', () => {
const mock = RequestMock()
.onRequestTo('http://example.com')
.respond();

expect(mock.requestFilterRules.length).eql(1);
expect(mock.requestFilterRules[0].options.url).eql('http://example.com');
});
});

Expand Down

0 comments on commit 3b13bc0

Please sign in to comment.