Skip to content

'Cannot find module' error with jest #2

Description

@julianna-langston

When I try to run jest tests against code that uses screen-reader-bridge v1.0.0, I get the following error:

Cannot find module 'screen-reader-bridge' from 'src/myFile.ts'

Require stack:
myFile.ts
myFile.test.ts

import {ScreenReaderBridge} from "screen-reader-bridge";

  at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:427:11)
 at Object.<anonymous> (myFile.ts:1:1)
 at Object.<anonymous> (myFile.test.ts:1:1)

Here's the relevant code

myFile.ts

import { ScreenReaderBridge } from "screen-reader-bridge";

// later
export const doSomething = () => {
  ScreenReaderBridge.addAriaAttributes(myDiv);
}

myFile.test.ts

import {doSomething} from "./myFile.test.ts";

My jest config looks like this:

/** @type {import('jest').Config} */
module.exports = {
    moduleDirectories: ["node_modules"],
    fakeTimers: {
        enableGlobally: true
    },
    transform: {
        "^.+\\.ts?$": ["ts-jest", {
            isolatedModules: true
        }]
    },
    testRegex: ".+\\.test\\.ts?$",
    testEnvironment: "jsdom"
};

Can you provide guidance on how to use screen-reader-bridge with Jest?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions