【发布时间】:2021-07-26 16:10:16
【问题描述】:
我正在尝试为我在 nodeJS 中实现的服务构建单元测试。 我知道我不能在我的测试文件中使用 import,所以我只在我的测试文件中使用了 require:
const typeorm = require("typeorm");
const DeviceService = require("./device.service.ts");
const Device = require("./entities/device.entity.ts");
const CreateDeviceDto = require("./dto/create-device.ts");
问题是我的 deviceService 中有一个导入。
当我运行测试时,我的文件 device.service.ts 出现错误:
import { Injectable } from '@nestjs/common';
^
SyntaxError: Unexpected token {
有关信息,我尝试在我的测试中使用这样的存根创建我的服务:
const deviceRepository = typeorm.getRepository(Device);
const stub = sinon.stub(deviceRepository, "create").returns(stubValue);
const DeviceServiceStubbed = new DeviceService(deviceRepository);
使用的堆栈:nestJs / Chai / Sinon / Typeorm
谢谢!
【问题讨论】:
标签: mocha.js nestjs sinon typeorm