utils.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import testUtils from '../_utils/utils';
  6. testUtils.createSinonSandbox();
  7. describe( 'utils', () => {
  8. describe( 'checkAssertions', () => {
  9. it( 'does not throw an error if at least one assertion passed', () => {
  10. const assertionRed = testUtils.sinon.stub().callsFake( () => {
  11. expect( 1 ).to.equal( 2 );
  12. } );
  13. const assertionGreen = testUtils.sinon.stub().callsFake( () => {
  14. expect( 1 ).to.equal( 1 );
  15. } );
  16. expect( () => {
  17. testUtils.checkAssertions( assertionRed, assertionGreen );
  18. } ).to.not.throw();
  19. } );
  20. it( 'throws all errors if any assertion did not pass', () => {
  21. const assertionRed = testUtils.sinon.stub().callsFake( () => {
  22. expect( 1 ).to.equal( 2 );
  23. } );
  24. const assertionGreen = testUtils.sinon.stub().callsFake( () => {
  25. expect( 2 ).to.equal( 1 );
  26. } );
  27. expect( () => {
  28. testUtils.checkAssertions( assertionRed, assertionGreen );
  29. } ).to.throw( Error, 'expected 1 to equal 2\n\nexpected 2 to equal 1' );
  30. } );
  31. it( 'does not execute all assertions if the first one passed', () => {
  32. const assertionRed = testUtils.sinon.stub().callsFake( () => {
  33. expect( 1 ).to.equal( 1 );
  34. } );
  35. const assertionGreen = testUtils.sinon.stub().callsFake();
  36. testUtils.checkAssertions( assertionRed, assertionGreen );
  37. expect( assertionGreen.called ).to.equal( false );
  38. } );
  39. } );
  40. } );