node-tap mocking alongside ts-node
See original GitHub issueThis 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:
- Created 2 years ago
- Comments:11
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok yeah, still has a typo in t.ts
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: