samedi 15 juin 2019

How to use supertest on route that accepts a file?

I'm mocking the file with mock-fs and using supertest to attach it, but I can't figure out how to mock the directory my code is using.

 it('should create a new image post', async (): Promise<void> => {
      mock({
        'test/assets': {
          'test.png': Buffer.from([8, 6, 7, 5, 3, 0, 9]),
        },
      });
      const type = 'image';
      const response = await request(app)
        .post(`/communities/${communityId}/posts?type=${type}`)
        .attach('image', 'test/assets/test.png')
        .set('Authorization', 'Bearer ' + token)
        .field({
          title,
        });
      expect(response.status).toEqual(200);
    });

The Error that I'm getting : Error { message: 'ENOENT, no such file or directory \'\\?\C:\Users\PC\Desktop\fullstack-reddit-clone\packages\server\images\2019-06-16T06-17-02.373Z-test.png\'', code: 'ENOENT', errno: -4058, path: '\\?\C:\Users\PC\Desktop\fullstack-reddit-clone\packages\server\images\2019-06-16T06-17-02.373Z-test.png', storageErrors: [] }

Aucun commentaire:

Enregistrer un commentaire