This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a new test util which executes specified assertions.
- Loading branch information
Kamil Piechaczek
committed
Nov 14, 2017
1 parent
68c5152
commit 6d33f78
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import testUtils from '../_utils/utils'; | ||
|
||
testUtils.createSinonSandbox(); | ||
|
||
describe( 'utils', () => { | ||
describe( 'checkAssertions', () => { | ||
it( 'does not throw an error if at least one assertion passed', () => { | ||
const assertionRed = testUtils.sinon.stub().callsFake( () => { | ||
expect( 1 ).to.equal( 2 ); | ||
} ); | ||
const assertionGreen = testUtils.sinon.stub().callsFake( () => { | ||
expect( 1 ).to.equal( 1 ); | ||
} ); | ||
|
||
expect( () => { | ||
testUtils.checkAssertions( assertionRed, assertionGreen ); | ||
} ).to.not.throw(); | ||
} ); | ||
|
||
it( 'throws all errors if any assertion did not pass', () => { | ||
const assertionRed = testUtils.sinon.stub().callsFake( () => { | ||
expect( 1 ).to.equal( 2 ); | ||
} ); | ||
const assertionGreen = testUtils.sinon.stub().callsFake( () => { | ||
expect( 2 ).to.equal( 1 ); | ||
} ); | ||
|
||
expect( () => { | ||
testUtils.checkAssertions( assertionRed, assertionGreen ); | ||
} ).to.throw( Error, 'expected 1 to equal 2\n\nexpected 2 to equal 1' ); | ||
} ); | ||
|
||
it( 'does not execute all assertion if the first one passed', () => { | ||
const assertionRed = testUtils.sinon.stub().callsFake( () => { | ||
expect( 1 ).to.equal( 1 ); | ||
} ); | ||
const assertionGreen = testUtils.sinon.stub().callsFake(); | ||
|
||
testUtils.checkAssertions( assertionRed, assertionGreen ); | ||
expect( assertionGreen.called ).to.equal( false ); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters