jeudi 16 juillet 2020

Is it possible to test for a value to be either null or a string while using Jest?

I have an object that bounces back and forth from one async function to another. I have a key that starts with a null value and at some point it is given a string.

I want to be able to have either a null or string pass a test in jest. Currently, the test passes for error.data when it returns null. But I need it to pass when it's either null or a string value.

it('returns robust themeId object', () => {
    return expect(auto.getThemeId(data1)).resolves.toEqual(expect.objectContaining({
      process: expect.any(String),
      themeId: expect.any(String),
      error: expect.arrayContaining([expect.objectContaining({
        data: null,
        description: expect.any(String),
        exitStatus: false
      })]),
      next: null
    }))
  })
})```

returningData: { process: 'get-theme-id',
themeId: '838',
error: [ { data: null, description: '', exitStatus: false} ],
next: null }

Aucun commentaire:

Enregistrer un commentaire