yeahoffline / redis-mock

Node.js redis client mock
212 stars 110 forks source link

How can I test the error result #183

Open raulrojasadl opened 3 years ago

raulrojasadl commented 3 years ago

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 commented 2 years ago

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