mardi 23 mars 2021

Accessing a function inside another file in Loopback4

 it("Provides Station Details", () => {
        
    const result = compareIssueDate('2021-03-01', '2020-03-09');
    console.log('Result: ', result)
    expect(result).to.have.status(200);
    console.log('Tested successfully..!!!')
   });

export function compareIssueDate(a: any, b: any) {

  const bandA = a.mlIssueDt;
  const bandB = b.mlIssueDt;

  let comparison = 0;
  if (bandA > bandB) {
    comparison = -1;
  } else if (bandA < bandB) {
    comparison = 1;
  }
  return comparison;
}

Path of compareIssueDate is as: getting-started/src/controllers/hello.controller.ts

Path of app.test.js (where above test is defined) is as: getting-started/test/app.test.js

import { compareIssueDate } from '../src/controllers/hello.controller';

If I use import statement, it gives error as: Cannot use import statement outside a module

const compareIssueDate = require("../src/controllers/hello.controller");

If I use require statement, it gives error as: Cannot find module '../src/controllers/hello.controller

How to access above function inside app.test.js. Please help. Thanks.

Aucun commentaire:

Enregistrer un commentaire