adobe / aio-lib-files

An abstraction on top of cloud blob storage exposing a file system like API
https://www.adobe.io
Apache License 2.0
10 stars 14 forks source link

global error tests should be rewritten as expect extentions #64

Open purplecabbage opened 4 years ago

purplecabbage commented 4 years ago

We have numerous instances of global.expect...

    // eslint-disable-next-line jest/expect-expect
    test('when path is not a valid string', async () => {
      await global.expectToThrowBadArg(files.delete.bind(files, 123), ['filePath', 'string'], { filePath: 123, options: {} })
    })

This means, we need to have many, many eslint-disable-next-line jest/expect-expect

A better practice, and the jest recommended way is to define our own expect extensions

expect.extend({
  toThrowBadArg: ( words, options ) => {
     // more expectations here ...
  }
})

// then tests call it like this:
expect(files.delete.bind(files, 123)).toThrowBadArg( ['filePath', 'string'], { filePath: 123, options: {} })

If we do this well, they can be reused across multiple repo/libs

purplecabbage commented 4 years ago

jest example here: https://jestjs.io/docs/en/expect#expectextendmatchers

aiojbot commented 4 years ago

JIRA issue created: https://jira.corp.adobe.com/browse/ACNA-938