This repository has been archived by the owner on Jun 9, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Turbo87/qunit
Add QUnit integration
- Loading branch information
Showing
5 changed files
with
59 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,34 @@ | ||
import { expect, util } from 'chai'; | ||
|
||
/** | ||
* Returns a function that calls the passed in function with a wrapped | ||
* expect() and the original `assert` as parameters. | ||
*/ | ||
export function withChai(fn) { | ||
return function(assert) { | ||
|
||
function _expect(...args) { | ||
let assertion = expect(...args); | ||
let originalAssert = assertion.assert; | ||
assertion.assert = function(...args) { | ||
let message = util.flag(assertion, 'message'); | ||
|
||
try { | ||
originalAssert.apply(this, args); | ||
assert.pushResult({ result: true, message }); | ||
|
||
} catch (error) { | ||
assert.pushResult({ | ||
result: false, | ||
actual: error.showDiff ? error.actual : undefined, | ||
expected: error.showDiff ? error.expected : undefined, | ||
message: error.message, | ||
}); | ||
} | ||
}; | ||
return assertion; | ||
} | ||
|
||
return fn.call(this, _expect, assert); | ||
}; | ||
} |
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
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,13 @@ | ||
import { test } from 'qunit'; | ||
import { withChai } from 'ember-cli-chai/qunit'; | ||
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance'; | ||
|
||
moduleForAcceptance('Acceptance | index'); | ||
|
||
test('visiting /', withChai(function(expect) { | ||
visit('/'); | ||
|
||
andThen(function() { | ||
expect(currentURL()).to.equal('/'); | ||
}); | ||
})); |
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
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