微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Loopback4 中访问另一个文件中的函数

如何解决在 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;
}

compareIssueDate 的路径为:getting-started/src/controllers/hello.controller.ts

app.test.js 的路径(上面定义了测试)为:getting-started/test/app.test.js

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

如果我使用import语句,它会报错:不能在模块外使用import语句

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

如果我使用 require 语句,它会给出如下错误Cannot find module '../src/controllers/hello.controller

如何在 app.test.js 中访问上述函数。请帮忙。 谢谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。