numberkruncher
numberkruncher
DDeno
Created by numberkruncher on 6/3/2024 in #help
error: TypeScript files are not supported in npm packages:
I am wondering why I cannot import a .ts file from a node_modules directory. If I could do this then I could use npm as a package manager which would allow me to take advantage of the things that I love about deno as well as being able to work with modules in a familiar way (eg. bundle templates, stylesheets, static assets, whatnot alongside the scripts). eg.
import { foo } from "./node_modules/abc/main.ts";
foo();
import { foo } from "./node_modules/abc/main.ts";
foo();
or
import { foo } from "@abc/main.ts";
foo();
import { foo } from "@abc/main.ts";
foo();
4 replies
DDeno
Created by numberkruncher on 5/17/2024 in #help
How to mock modules like you can with jest?
With node/jest I was able to mock specific functions from modules using jest.mock at the start of the test file. How can I do this in Deno? I have a module which calls a function from another module:
import {foo} from "foo";

export function bar(a: number): number {
return foo(a * 2);
}
import {foo} from "foo";

export function bar(a: number): number {
return foo(a * 2);
}
How can I substitute foo with a mock/stub/fake for the scope of a test file?
jest.mock("foo", () => ({
foo: jest.fn();
}));

import {foo} from "foo";

describe("example", () => {
it("returns the expected number", () => {
foo.mockImplementation((_) => 100);
...
jest.mock("foo", () => ({
foo: jest.fn();
}));

import {foo} from "foo";

describe("example", () => {
it("returns the expected number", () => {
foo.mockImplementation((_) => 100);
...
3 replies