Testcafe: RequestMock returns 222 "unknown"

Created on 11 Jul 2018  路  2Comments  路  Source: DevExpress/testcafe

Are you requesting a feature or reporting a bug?

Bug

What is the current behavior?

The request was intercepted, but returns 222 "unknown" on status code even with respond(null, 500).

What is the expected behavior?

Request need to return status 500 after call.

Test code
I used a jsonplaceholder to test once the final API URL can't be shared, but it's the same idea and got the same problem.

const mock = RequestMock()
    .onRequestTo('https://jsonplaceholder.typicode.com/posts/1')
    .respond(null, 500);

fixture`Summary account errors`.requestHooks(mock);

test('Error scenario: request with status code 500', async t =>
    await t
        .navigateTo(PAGE_URL)
        .debug());

Specify your

  • operating system: Ubuntu 16.04
  • testcafe version: 0.20.4
  • node.js version: 8.11.2
Auto-locked question

Most helpful comment

Hi @salesgu

Thank you for your report.
Your test page performs a cross-domain ajax request to the mocked url. The mocked url should pass a CORS validation. 222 is an internal status code that means request failed the CORS validation.

You should to modify your code as follows:

const mock = RequestMock()
    .onRequestTo('https://jsonplaceholder.typicode.com/posts/1')
    .respond(null, 500, {'access-control-allow-origin': '*'});

Also I've added a clear warning message for this case - https://github.com/DevExpress/testcafe/commit/3cd7b7d61359a6200e8204534b1a3d25ba6c5435

All 2 comments

Hi @salesgu

Thank you for your report.
Your test page performs a cross-domain ajax request to the mocked url. The mocked url should pass a CORS validation. 222 is an internal status code that means request failed the CORS validation.

You should to modify your code as follows:

const mock = RequestMock()
    .onRequestTo('https://jsonplaceholder.typicode.com/posts/1')
    .respond(null, 500, {'access-control-allow-origin': '*'});

Also I've added a clear warning message for this case - https://github.com/DevExpress/testcafe/commit/3cd7b7d61359a6200e8204534b1a3d25ba6c5435

This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.

Was this page helpful?
0 / 5 - 0 ratings