utils.js 868 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * General test utils for CKEditor.
  7. */
  8. const utils = {
  9. /**
  10. * Creates Sinon sandbox in {@link bender#sinon} and plugs `afterEach()` callback which
  11. * restores all spies and stubs created in this sandbox.
  12. *
  13. * See https://github.com/ckeditor/ckeditor5-design/issues/72 and http://sinonjs.org/docs/#sinon-sandbox
  14. *
  15. * Usage:
  16. *
  17. * // Directly in the test file:
  18. * testUtils.createSinonSandbox();
  19. *
  20. * // Then inside tests you can use bender.sinon:
  21. * it( 'does something', () => {
  22. * testUtils.sinon.spy( obj, 'method' );
  23. * } );
  24. */
  25. createSinonSandbox() {
  26. before( () => {
  27. utils.sinon = sinon.sandbox.create();
  28. } );
  29. afterEach( () => {
  30. utils.sinon.restore();
  31. } );
  32. }
  33. };
  34. export default utils;