Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error doesn't handle in the respond of the RequestMock #6703

Closed
Aleksey28 opened this issue Nov 18, 2021 · 1 comment · Fixed by #7112
Closed

Error doesn't handle in the respond of the RequestMock #6703

Aleksey28 opened this issue Nov 18, 2021 · 1 comment · Fixed by #7112
Assignees
Labels
FREQUENCY: level 1 SYSTEM: request hooks TYPE: bug The described behavior is considered as wrong (bug).

Comments

@Aleksey28
Copy link
Collaborator

Aleksey28 commented Nov 18, 2021

What is your Scenario?

I have a code with an error in the RequestMock.respond.

What is the Current behavior?

If I don't make an error handler for my code there the test will hang.

What is the Expected behavior?

The test shouldn't hang

What is your public website URL? (or attach your complete example)

In this example, I only use API https://jsonplaceholder.typicode.com/todos/1

What is your TestCafe test code?

import { ClientFunction, RequestMock } from 'testcafe';

const mock = RequestMock()
    .onRequestTo('https://devexpress.github.io/testcafe/example/todo')
    .respond(async (req, res) => {
        let body = {};

        //try {
            body = await fetch('https://jsonplaceholder.typicode.com/todos/1').then(data => data.json());
        //}
        //catch (err) {
        //    console.log(err);
        //}

        res.headers['access-control-allow-origin'] = '*';
        res.setBody(body);
    });

fixture`RequestMock.onRequestTo`
    .requestHooks(mock);

test('Should mock requests', async t => {
    const jsonData    = await ClientFunction(() => fetch('https://devexpress.github.io/testcafe/example/todo').then(res => res.json()))();

    await t
        .expect(jsonData).eql({
            userId:    1,
            id:        1,
            title:     'delectus aut autem',
            completed: false,
        });
});

Your complete configuration file

No response

Your complete test report

No response

Screenshots

No response

Steps to Reproduce

  1. Create file test.js
  2. Put to it test code
  3. Run testcafe chrome ./test.js

TestCafe version

1.16.1

Node.js version

14.18.1

Command-line arguments

chrome ./test.js

Browser name(s) and version(s)

Chrome 96.0.4664.45

Platform(s) and version(s)

Windows 10

Other

No response

@Aleksey28 Aleksey28 added the TYPE: bug The described behavior is considered as wrong (bug). label Nov 18, 2021
@Aleksey28 Aleksey28 changed the title Fetch is undefined in the respond of the RequestMock Error doesn't handle in the respond of the RequestMock Nov 18, 2021
@miherlosev miherlosev self-assigned this Jun 27, 2022
@github-actions
Copy link

github-actions bot commented Jul 8, 2022

Release v1.20.0-rc.1 addresses this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FREQUENCY: level 1 SYSTEM: request hooks TYPE: bug The described behavior is considered as wrong (bug).
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants