rquellh / testcafe-cucumber

Integration of TestCafe and CucumberJS
MIT License
95 stars 59 forks source link

Mocking HTTP Requests #29

Open JacekWalczak92 opened 5 years ago

JacekWalczak92 commented 5 years ago

Hello, Can you give an example, how to implement the mocking feature to your tests? According to testCafe, for mock response from server we need to write:

import { RequestLogger, RequestMock } from 'testcafe';

const logger = RequestLogger('http://example.com'); const mock = RequestMock() .onRequestTo('http://external-service.com/api/') .respond({ data: 'value' });

fixture My fixture .page('http://example.com') .requestHooks(logger);

test .requestHooks(mock) ('My test', async t => { await t .click('#send-logged-request') .expect(logger.count(() => true)).eql(1) .removeRequestHooks(logger) .click('#send-unlogged-request') .expect(logger.count(() => true)).eql(1) .addRequestHooks(logger) .click('#send-logged-request') .expect(logger.count(() => true)).eql(2); })

But I can not find fixtures and tests in your steps.

gajo4256 commented 5 years ago

@JacekWalczak92 what you could do is add mock to testController using addRequestHooks method, e.g.: await testController.addRequestHooks(mock);

You could add this anywhere where you have testControllerpresent. In your case above testController is t object