question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

node-tap mocking alongside ts-node

See original GitHub issue

This might work better as a different issue type, if so let me know.

Expected Behavior

I am able to mock require

Actual Behavior

I receive this relatively unhelpful (to me) error stack

    Object.<anonymous> (test/dosStub.ts:8:3)

    Module.m._compile (node_modules/ts-node/src/index.ts:1225:23)

    Object.require.extensions.<computed> [as .ts] (node_modules/ts-node/src/index.ts:1228:12)

Steps to reproduce the problem

This is probably partly related to the node-tap’s way of mocking, which is documented here. https://node-tap.org/docs/api/mocks/#api

Minimal reproduction

Since my code is already quite short, pasting it here in it’s entirety

import t from "tap";
const { DosStub} = t.mock("../lib/dosStub.ts", {
  console: {
    error: () => {}
  }
});

t.test("DosStub", (t) => {
  t.throws(function() {new DosStub()}, 'foo')
  t.done
});

The contents of the dosStub.ts file are a single exported class. Since this is a require error, I don’t think the content of that file are relevant, but I will share if desired.

https://github.com/TypeStrong/ts-node-repros/pull/15

Specifications

  • ts-node version: v10.1.0
  • node version: v14.16.1
  • TypeScript version: v4.3.5
  • tsconfig.json, if you’re using one:
{ }
  
  • Operating system and version:
  • If Windows, are you using WSL or WSL2?:

Description: Manjaro Linux Release: 21.1.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
cspotcodecommented, Aug 7, 2021

Ok yeah, still has a typo in t.ts

1reaction
cspotcodecommented, Aug 5, 2021

Yes, please test this locally, and when you’re sure it is correct, I’ll rerun the reproduction.

On Thu, Aug 5, 2021, 12:13 AM Drazi Crendraven @.***> wrote:

There are two commits since I’m editing on web on mobile. I think the typo was fixed with the second one? Otherwise I’m not seeing it and will have to review tomorrow

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/TypeStrong/ts-node/issues/1417#issuecomment-893149923, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAC35OA74K6LVGV7RBB4Z6TT3IFYDANCNFSM5BSOC66Q .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using tap with TypeScript - Node Tap
Using tap with TypeScript. First, install typescript and ts-node . Name your test files .ts and they'll be loaded as TypeScript if you...
Read more >
How to mock a dependency in a Node.js, and why you should ...
Programmers working with the test-driven development (TDD) method make use of mock objects when writing software. Mock objects meet the interface ...
Read more >
test .ts class by node-tap - Stack Overflow
install tap globally: npm i -g tap after that, put this code on package.json "test": "tap --node-arg=--require=ts-node/register",.
Read more >
Test your Fastify REST API With Node Tap - YouTube
In this video, we test a Fastify REST API with Node Tap. You will learn how to mock imports and test against a...
Read more >
Sinon.JS - Standalone test fakes, spies, stubs and mocks for ...
Standalone test spies, stubs and mocks for JavaScript. Works with any unit testing framework. ... Node and CommonJS build systems.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found