Skip to content

Commit

Permalink
Merge pull request #36 from iambumblehead/small-update-to-readme
Browse files Browse the repository at this point in the history
updated README
  • Loading branch information
iambumblehead authored Dec 4, 2021
2 parents 872aa98 + 86b6086 commit 011e102
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# changelog

* 1.6.3 _Dec.04.2021_
* adds more examples to README
* 1.6.2 _Dec.04.2021_
* adds uvu tests and example command to README
* 1.6.1 _Dec.03.2021_
Expand Down
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,11 @@ unit-test examples, using `esmock` and `ava` for various situations
import test from 'ava';
import esmock from 'esmock';

test('should mock local files, packages and core modules', async t => {
test('should mock local files and packages', async t => {
const main = await esmock('../src/main.js', {
fs: { readFileSync: () => 'give it a star' },
stringifierpackage : o => JSON.stringify(o),
'../src/hello.js' : {
default : () => 'world'
},
'../src/util.js' : {
default : () => 'world',
exportedFunction : () => 'foobar'
}
});
Expand All @@ -64,7 +61,7 @@ test('should do global instance mocks —third parameter', async t => {
});

test('should mock "await import()" using esmock.p', async t => {
// using esmock.p, mock definitions are not deleted from cache
// using esmock.p, mock definitions are kept in cache
const doAwaitImport = await esmock.p('../awaitImportLint.js', {
eslint : { ESLint : cfg => cfg }
});
Expand All @@ -74,4 +71,22 @@ test('should mock "await import()" using esmock.p', async t => {

esmock.purge(doAwaitImport); // clear cache, if you wish
});

test('should merge "default" value, when safe', async t => {
const main = await esmock('../src/main.js');

// use the form you prefer in your test
t.is(main(), main.default());
});

test('should mock "default" value, when safe', async t => {
const mainA = await esmock('../src/exportsMain.js', {
'../src/main.js' : () => 'mocked main'
});
const mainB = await esmock('../src/exportsMain.js', {
'../src/main.js' : { default : () => 'mocked main' }
});

t.is(mainA(), mainB());
});
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "esmock",
"version": "1.6.2",
"version": "1.6.3",
"license": "MIT",
"readmeFilename": "README.md",
"description": "provides native ESM import mocking for unit tests",
Expand Down
15 changes: 15 additions & 0 deletions spec/ava/esmock.ava.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,18 @@ test('should have small querystring in stacktrace filename, deep', async t => {

t.pass();
});

test.only('should merge "default" value, when safe', async t => {
const main = await esmock('../local/main.js');

t.is(main(), main.default());

const mockMainA = await esmock('../local/exportsMain.js', {
'../local/main.js' : () => 'mocked main'
});
const mockMainB = await esmock('../local/exportsMain.js', {
'../local/main.js' : { default : () => 'mocked main' }
});

t.is(mockMainA(), mockMainB());
});
3 changes: 3 additions & 0 deletions spec/local/exportsMain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import main from './main.js';

export default main;

0 comments on commit 011e102

Please sign in to comment.