Skip to content

Commit 638da1d

Browse files
committed
WIP: expectAssertion updates
1 parent 884baf3 commit 638da1d

File tree

3 files changed

+57
-70
lines changed

3 files changed

+57
-70
lines changed

addon-test-support/asserts/assertion.js

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,38 @@ let TestAdapter = QUnitAdapter.extend({
1212

1313
let noop = () => {};
1414

15-
function reset(origTestAdapter, origLoggerError) {
15+
let cleanup = (origTestAdapter, origLoggerError) => {
1616
// Cleanup the test adapter and restore the original.
17-
Ember.run(() => {
17+
return Ember.run(() => {
1818
Ember.Test.adapter.destroy();
1919
Ember.Test.adapter = origTestAdapter;
2020
Ember.Logger.error = origLoggerError;
2121
});
22-
}
22+
};
2323

24-
function handleError(syncErrorInCallback) {
25-
let error = syncErrorInCallback || Ember.Test.adapter.lastError;
26-
let isEmberError = error instanceof Ember.Error;
27-
let matches = Boolean(isEmberError && checkMatcher(error.message, matcher));
24+
let handleError = (context, error, matcher, isProductionBuild) => {
25+
let isEmberError = error instanceof Ember.Error;
26+
let matches = Boolean(isEmberError && checkMatcher(error.message, matcher));
27+
let errObj = {};
2828

29-
if (isProductionBuild) {
30-
this.pushResult({
31-
result: true,
32-
actual: null,
33-
expected: null,
34-
message: 'Assertions are disabled in production builds.'
35-
});
36-
} else {
37-
this.pushResult({
38-
result: isEmberError && matches,
39-
actual: error && error.message,
40-
expected: matcher,
41-
message: matcher ? 'Ember.assert matched specific message' : 'Ember.assert called with any message'
42-
});
43-
}
44-
}
29+
if (isProductionBuild) {
30+
errObj = {
31+
result: true,
32+
actual: null,
33+
expected: null,
34+
message: 'Assertions are disabled in production builds.'
35+
};
36+
} else {
37+
errObj = {
38+
result: isEmberError && matches,
39+
actual: error && error.message,
40+
expected: matcher,
41+
message: matcher ? 'Ember.assert matched specific message' : 'Ember.assert called with any message'
42+
};
43+
}
44+
45+
context.pushResult(errObj);
46+
};
4547

4648
export default function() {
4749
let isProductionBuild = (function() {
@@ -71,13 +73,18 @@ export default function() {
7173
error = e;
7274
}
7375

74-
if (result && typeof result.then === 'function') {
76+
if (error) {
77+
handleError(this, error, matcher, isProductionBuild);
78+
} else if (Ember.Test.adapter.lastError) {
79+
handleError(this, Ember.Test.adapter.lastError, matcher, isProductionBuild);
80+
} else if(result && typeof result === 'object' && result !== null && typeof result.then === 'function') {
7581
return result
76-
.then(null, () => handleError(error))
82+
.then(null, () => handleError(this, error, matcher, isProductionBuild))
7783
.finally(() => cleanup(origTestAdapter, origLoggerError));
84+
} else {
85+
handleError(this, null, matcher, null);
7886
}
79-
8087

81-
cleanup(origTestAdapter, origLoggerError);
88+
return cleanup(origTestAdapter, origLoggerError);
8289
};
8390
}

tests/helpers/module-for-assert.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

tests/helpers/setup-assert-test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import QUnit from 'qunit';
2+
3+
export default function setupAssertTest(hooks) {
4+
hooks.beforeEach(function() {
5+
let originalPushResult = QUnit.assert.pushResult;
6+
this.pushedResults = [];
7+
8+
QUnit.assert.pushResult = (result) => {
9+
this.pushedResults.push(result);
10+
};
11+
12+
this.restoreAsserts = () => {
13+
if (originalPushResult) {
14+
QUnit.assert.pushResult = originalPushResult;
15+
originalPushResult = null;
16+
}
17+
};
18+
});
19+
20+
hooks.afterEach(function() {
21+
this.restoreAsserts();
22+
});
23+
}

0 commit comments

Comments
 (0)