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

How can I test the error result #183

Open
raulrojasadl opened this issue Mar 17, 2021 · 1 comment
Open

How can I test the error result #183

raulrojasadl opened this issue Mar 17, 2021 · 1 comment

Comments

@raulrojasadl
Copy link

Hi dear friends,

I want to know what is the right way to test the error result, In my test code I use

jest.mock("redis", () => jest.requireActual("redis-mock"));

describe("redis functions tests OK", () => {......}

But always I can test the success results very easy, for example:

const set = (key, data, dbOptions) =>
  new Promise((resolve, reject) =>
    createClient(dbOptions)
      .then((client) =>
        client.set(key, data, (err, res) => (err ? reject(err) : resolve(res)))
      )
      .catch(reject)
  );

This, works fine.

it("set success", async () =>
    await expect(redisFunctions.set("key", "hello", dbOptions)).resolves.toBe(
      "OK"
    ));

But, I don't know how to return an Error in client.set(key, data, (err, res) using redis-mock with the current configuration.

Thanks for your help.

@jacobbogers
Copy link

Would be cool to have this feature, so I can test error paths in the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants