-
-
Notifications
You must be signed in to change notification settings - Fork 770
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also fixes the linting issues and some feedback from the PR.
- Loading branch information
Showing
5 changed files
with
31 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export default function (){ return 42; } | ||
export default function () { return 42; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export default { | ||
anExport(){ return 42; } | ||
} | ||
anExport() { return 42; } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export function anExport(){ return 42; } | ||
export function anExport() { return 42; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,57 @@ | ||
"use strict"; | ||
|
||
import referee from "referee"; | ||
import sinon from "../../lib/sinon"; | ||
import * as aModule from "./a-module"; | ||
import aModuleWithDefaultExport from "./a-module-with-default"; | ||
|
||
// Usually one would import the default module, but one can make a form of wrapper like this | ||
/* eslint-disable no-unused-vars */ | ||
import functionModule, * as functionModuleAlternative from "./a-function-module"; | ||
const {assert, refute} = referee; | ||
|
||
function createTestSuite(action){ | ||
function createTestSuite(action) { | ||
var stub; | ||
var errorRegEx = /TypeError: ES Modules cannot be (stubbed|spied)/; | ||
|
||
afterEach(function() { | ||
stub && stub.restore && stub.restore(); | ||
}); | ||
describe("sinon." + action + "()", function () { | ||
|
||
describe("sinon." + action + "()", function(){ | ||
describe("Modules with objects as their default export", function() { | ||
afterEach(function() { | ||
stub && stub.restore && stub.restore(); | ||
}); | ||
it("should NOT result in error", function() { | ||
refute.exception(function() { | ||
afterEach(function () { | ||
if (stub && stub.restore) { stub.restore(); } | ||
}); | ||
|
||
describe("Modules with objects as their default export", function () { | ||
|
||
it("should NOT result in error", function () { | ||
refute.exception(function () { | ||
stub = sinon[action](aModuleWithDefaultExport, "anExport"); | ||
}); | ||
}); | ||
|
||
it("should spy/stub an exported function", function() { | ||
it("should spy/stub an exported function", function () { | ||
stub = sinon[action](aModuleWithDefaultExport, "anExport"); | ||
aModuleWithDefaultExport.anExport(); | ||
aModuleWithDefaultExport.anExport(); | ||
assert(stub.callCount === 2); | ||
}); | ||
}); | ||
|
||
describe("Modules without default export", function() { | ||
it("should give a proper error message", function() { | ||
assert.exception(function() { | ||
describe("Modules without default export", function () { | ||
it("should give a proper error message", function () { | ||
assert.exception(function () { | ||
sinon[action](aModule, "anExport"); | ||
}, errorRegEx); | ||
}); | ||
}); | ||
|
||
describe("Modules that exports a function as their default export", function() { | ||
it("should not be possible to spy/stub the default export using a wrapper for the exports", function() { | ||
assert.exception(function() { | ||
describe("Modules that exports a function as their default export", function () { | ||
it("should not be possible to spy/stub the default export using a wrapper for the exports", function () { | ||
assert.exception(function () { | ||
stub = sinon[action](functionModuleAlternative, "anExport"); | ||
}, errorRegEx); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
createTestSuite('stub'); | ||
createTestSuite('spy'); | ||
createTestSuite("stub"); | ||
createTestSuite("spy"); |