https://github.com/mjethani/esm-world
An ES module loader for BDD-style testing
https://github.com/mjethani/esm-world
bdd esm nodejs
Last synced: 2 months ago
JSON representation
An ES module loader for BDD-style testing
- Host: GitHub
- URL: https://github.com/mjethani/esm-world
- Owner: mjethani
- License: isc
- Created: 2021-08-14T22:23:37.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-08-18T20:23:28.000Z (over 3 years ago)
- Last Synced: 2025-02-13T11:04:28.031Z (2 months ago)
- Topics: bdd, esm, nodejs
- Language: JavaScript
- Homepage:
- Size: 27.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This is an ES module loader for BDD-style testing.
```js
/* index.js */let instance = null;
export class MySingleton {
constructor() {
if (instance !== null)
throw new Error('Only a single instance is supported');instance = this;
}sayFoo() {
console.log('Foo!');
}sayBar() {
console.log('Bar!');
}
}
``````js
/* test.js */import { strict as assert } from 'assert';
import { createWorld } from 'esm-world';
let mockConsole = new (class MockConsole {
log(message) {
this.message = message;
}
})();describe('MySingleton', () => {
let instance = null;beforeEach(async () => {
// Load module in a new world.
let { MySingleton } = await createWorld('./index.js', { globals: { console: mockConsole } });instance = new MySingleton();
});describe('#sayFoo()', () => {
it('should say foo', () => {
instance.sayFoo();assert.equal(mockConsole.message, 'Foo!');
});
});describe('#sayBar()', () => {
it('should say bar', () => {
instance.sayBar();assert.equal(mockConsole.message, 'Bar!');
});
});
});
```It needs the `--experimental-vm-modules` option to Node.js and is meant for testing with the [Mocha](https://mochajs.org/) framework only for now.
Under development.