GithubHelp home page GithubHelp logo

Comments (2)

SmashingQuasar avatar SmashingQuasar commented on May 22, 2024 1

@iambumblehead Hey!

Thanks for your super-quick answer!

Actually I figured out what I was doing wrong just before I read your answer. It was indeed because I was not using the returned mocked module and was attempting to use the native one. I probably misread the documentation, my bad!

It works perfectly using .mts and Sinon. Thanks for your work, this library works like a charm, it totally solved my issue!
It's unfortunate that the syntax is this heavy but I understand there is most likely no other way to do this as of today.

from esmock.

iambumblehead avatar iambumblehead commented on May 22, 2024

@SmashingQuasar thanks for opening this issue. Two things, one: only the esmock-returned Response will use the mocked import tree and so that is the Response definition that should be used in the test,

-import { Response } from "../../../../src/main/Web/Server/Response.mjs";


-await esmock(
+const { Response } = await esmock(
	"../../../../src/main/Web/Server/Response.mts",
	import.meta.url,
	{
		zlib: {
			createGzip: {
				pipe: () =>
				{
					console.debug("pipe called 2");
				}
			}
		}
	}
);

The other thing is that esmock's scripted resolver might not handle the 'mts' extension correctly. If that's the case, run the test process with --experimental-import-meta-resolve to use node's native resolver. If --experimental-import-meta-resolve is needed, please open an issue here and I'll resolve the scripted resolver issue :)

esmock's own unit-tests are run twice for each test folder, one time with and another without --experimental-import-meta-resolve so example calls are seen there, for example this https://github.com/iambumblehead/esmock/blob/master/tests/tests-nodets/package.json#L17

esmock should work for your use-case

from esmock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.