8
0

tools.js 1.5 KB

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