Skip to content

Document how to configure Node to allow stubbing EcmaScript modules #1832

@fatso83

Description

@fatso83

EcmaScript modules that run in an environment supporting them (meaning they haven't been transpiled using Babel to ES5) and export a default function of some kind cannot be stubbed, as ES namespaces are immutable per the spec. There is nothing Sinon can do about this, so we explicitly throw an error when you try to do this: 'ES Modules cannot be stubbed'.

But @jdalton has made esm, a runtime loader for Node that enables loading EcmaScript modules (*.mjs), and to allow stubbing using Sinon and the like, he has added the mutableNamespace option to esm.

There should be an article under our How to section that shows how one can set up npm to execute node using esm and the option, along with a test script.

References:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions