-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
88 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/* globals bender, before, afterEach, sinon */ | ||
|
||
'use strict'; | ||
|
||
( function() { | ||
/** | ||
* Test tools for CKEditor. | ||
* | ||
* This is a main namespace for the test tools. | ||
* | ||
* * General tools go directly to `bender.tools.*`. | ||
* * Core tools (introduced by `ckeditor5-core`) go to `bender.tools.core.*`. | ||
* * Plugin tools (introduced by plugins) go to `bender.tools.plugin.<plugin-name>.*`. | ||
* | ||
* Tools for specific plugins or the core should be kept in `tests/_tools/tools.js` file | ||
* of the respective repository. They can be loaded using Bender's `bender-include` directive. | ||
* Their tests should be kept in `tests/bender/*` directory. | ||
*/ | ||
bender.tools = { | ||
/** | ||
* Creates Sinon sandbox in {@link bender#sinon} and plugs `afterEach()` callback which | ||
* restores all spies and stubs created in this sandbox. | ||
* | ||
* See https://github.com/ckeditor/ckeditor5-design/issues/72 and http://sinonjs.org/docs/#sinon-sandbox | ||
* | ||
* Usage: | ||
* | ||
* // Directly in the test file: | ||
* bender.tools.createSinonSandbox(); | ||
* | ||
* // Then inside tests you can use bender.sinon: | ||
* it( 'does something', function() { | ||
* bender.sinon.spy( obj, 'method' ); | ||
* } ); | ||
*/ | ||
createSinonSandbox() { | ||
before( function() { | ||
bender.sinon = sinon.sandbox.create(); | ||
} ); | ||
|
||
afterEach( function() { | ||
bender.sinon.restore(); | ||
} ); | ||
} | ||
}; | ||
} )(); |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var obj = { | ||
method() {} | ||
}; | ||
var spy; | ||
var origMethod = obj.method; | ||
|
||
bender.tools.createSinonSandbox(); | ||
|
||
describe( 'bender.tools.createSinonSandbox()', function() { | ||
it( 'creates a sandbox', function() { | ||
expect( bender.sinon ).to.be.an( 'object' ); | ||
expect( bender.sinon ).to.have.property( 'spy' ); | ||
} ); | ||
|
||
// This test is needed for the following one. | ||
it( 'really works', function() { | ||
spy = bender.sinon.spy( obj, 'method' ); | ||
|
||
expect( obj ).to.have.property( 'method', spy ); | ||
} ); | ||
|
||
it( 'restores spies after each test', function() { | ||
obj.method(); | ||
|
||
sinon.assert.notCalled( spy ); | ||
expect( obj ).to.have.property( 'method', origMethod ); | ||
} ); | ||
} ); |