jeudi 30 juillet 2020

How to suppress Jest Linter errors from import files?

So I'm trying to do some basic API testing with Jest by importing a function from handler.ts but Jest crawls through the handler ts imports and gives me linter errors for a file that handler importest from my libs folder when all I want to do is check if the result of that function equals what I want it to equal.

Here's my test file test/handler.test.ts:

import { getInbox } from './../handler'
import * as myMongo from '../../../libs/mongo';
import { Db } from 'mongodb';

const productionDbPromise: Promise<Db> = myMongo.getProductionDb();

test("Case page 1, limit 5", async ()=>{
    const page = 1;
    const limit = 5;
    const event = {
        queryStringParameters: {
            page: page,
            limit: limit
        }
    };
    const productionDb = await productionDbPromise;
    const seekerCollection = productionDb.collection('seekers');
    const totalDocs = await seekerCollection.countDocuments({ lastMessageDate: { $ne: null } });
    const code = 200;
    const status = 'OK';
    const res: any = await getInbox(event);
    expect(res.code).toEqual(code);
    expect(res.status).toEqual(status);
    expect(res.json().totalDocs).toEqual(totalDocs);
    expect(res.json().seekers.length).toEqual(limit);
});

And here's the error:

Test suite failed to run

    TypeError: twilio is not a function

      6 | export const client = twilio(accountSid, authToken);
      7 | export const messagingServiceSid = process.env.TWILIO_SERVICE_ID;
    > 8 | 
        | ^

      at Object.<anonymous> (../../libs/twilio.ts:8:18)
      at Object.<anonymous> (../../libs/message.ts:7:18)
      at Object.<anonymous> (handler.ts:14:19)
      at Object.<anonymous> (__test__/handler.test.ts:4:19)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        12.086 s
npm ERR! Test failed.  See above for more details.

Any idea how to get it to ignore this? (which by the way the function I'm testing does not even use any exports from that libs file, and the twilio object is correctly imported on the first line of that file)

Aucun commentaire:

Enregistrer un commentaire