utils.js 983 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 before, afterEach, sinon */
  7. 'use strict';
  8. /**
  9. * General test utils for CKEditor.
  10. */
  11. const utils = {
  12. /**
  13. * Creates Sinon sandbox in {@link bender#sinon} and plugs `afterEach()` callback which
  14. * restores all spies and stubs created in this sandbox.
  15. *
  16. * See https://github.com/ckeditor/ckeditor5-design/issues/72 and http://sinonjs.org/docs/#sinon-sandbox
  17. *
  18. * Usage:
  19. *
  20. * // Directly in the test file:
  21. * testUtils.createSinonSandbox();
  22. *
  23. * // Then inside tests you can use bender.sinon:
  24. * it( 'does something', () => {
  25. * testUtils.sinon.spy( obj, 'method' );
  26. * } );
  27. */
  28. createSinonSandbox() {
  29. before( () => {
  30. utils.sinon = sinon.sandbox.create();
  31. } );
  32. afterEach( () => {
  33. utils.sinon.restore();
  34. } );
  35. }
  36. };
  37. export default utils;