tools.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* jshint node: false, browser: true, globalstrict: true */
  6. /* globals bender, before, afterEach, sinon */
  7. 'use strict';
  8. ( () => {
  9. /**
  10. * Test tools for CKEditor.
  11. *
  12. * This is a main namespace for the test tools.
  13. *
  14. * * General tools go directly to `bender.tools.*`.
  15. * * Core tools (introduced by `ckeditor5-core`) go to `bender.tools.core.*`.
  16. * * Plugin tools (introduced by plugins) go to `bender.tools.plugin.<plugin-name>.*`.
  17. *
  18. * Tools for specific plugins or the core should be kept in `tests/_tools/tools.js` file
  19. * of the respective repository. They can be loaded using Bender's `bender-include` directive.
  20. * Their tests should be kept in `tests/bender/*` directory.
  21. */
  22. bender.tools = {
  23. /**
  24. * Creates Sinon sandbox in {@link bender#sinon} and plugs `afterEach()` callback which
  25. * restores all spies and stubs created in this sandbox.
  26. *
  27. * See https://github.com/ckeditor/ckeditor5-design/issues/72 and http://sinonjs.org/docs/#sinon-sandbox
  28. *
  29. * Usage:
  30. *
  31. * // Directly in the test file:
  32. * bender.tools.createSinonSandbox();
  33. *
  34. * // Then inside tests you can use bender.sinon:
  35. * it( 'does something', () => {
  36. * bender.sinon.spy( obj, 'method' );
  37. * } );
  38. */
  39. createSinonSandbox() {
  40. before( () => {
  41. bender.sinon = sinon.sandbox.create();
  42. } );
  43. afterEach( () => {
  44. bender.sinon.restore();
  45. } );
  46. }
  47. };
  48. } )();