Skip to content

Commit d31dca8

Browse files
committed
feat(empower): support assertion methods with three or more arguments
1 parent 5766063 commit d31dca8

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

lib/enhance.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,7 @@ function enhance (target, formatter, config) {
7878
}
7979
var methodName = detectMethodName(matcher.calleeAst());
8080
if (methodName && typeof target[methodName] === 'function') {
81-
switch (len) {
82-
case 1:
83-
enhancement[methodName] = decorateArgs(len, target, target[methodName], doPowerAssert);
84-
break;
85-
case 2:
86-
enhancement[methodName] = decorateArgs(len, target, target[methodName], doPowerAssert);
87-
break;
88-
default:
89-
throw new Error('not supported');
90-
}
81+
enhancement[methodName] = decorateArgs(len, target, target[methodName], doPowerAssert);
9182
}
9283
});
9384

test/buster_assertions_test.js

+37-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
path: '/path/to/some_test.js',
2020
patterns: [
2121
'assert(actual, [message])',
22+
'assert.isNull(object, [message])',
2223
'assert.same(actual, expected, [message])',
23-
'assert.isNull(object, [message])'
24+
'assert.near(actual, expected, delta, [message])'
2425
]
2526
};
2627
return espowerSource(line, '/path/to/some_test.js', options);
@@ -39,8 +40,9 @@
3940
var assert = empower(busterAssertions.assert, fakeFormatter, {
4041
patterns: [
4142
'assert(actual, [message])',
43+
'assert.isNull(object, [message])',
4244
'assert.same(actual, expected, [message])',
43-
'assert.isNull(object, [message])'
45+
'assert.near(actual, expected, delta, [message])'
4446
]
4547
});
4648

@@ -126,4 +128,37 @@
126128
});
127129
});
128130

131+
132+
suite('buster assertion method with three arguments', function () {
133+
test('when every argument is Identifier', function () {
134+
var actualVal = 10.6, expectedVal = 10, delta = 0.5;
135+
try {
136+
eval(weave('assert.near(actualVal, expectedVal, delta);'));
137+
assert.ok(false, 'AssertionError should be thrown');
138+
} catch (e) {
139+
baseAssert.equal(e.name, 'AssertionError');
140+
baseAssert.equal(e.message, [
141+
'[assert.near] /path/to/some_test.js',
142+
'assert.near(actualVal, expectedVal, delta)',
143+
'[{"value":10.6,"espath":"arguments/0"},{"value":10,"espath":"arguments/1"},{"value":0.5,"espath":"arguments/2"}]: Expected 10.6 to be equal to 10 +/- 0.5'
144+
].join('\n'));
145+
}
146+
});
147+
148+
test('optional fourth argument', function () {
149+
var actualVal = 10.6, expectedVal = 10, delta = 0.5, messageStr = 'not in delta';
150+
try {
151+
eval(weave('assert.near(actualVal, expectedVal, delta, messageStr);'));
152+
assert.ok(false, 'AssertionError should be thrown');
153+
} catch (e) {
154+
baseAssert.equal(e.name, 'AssertionError');
155+
baseAssert.equal(e.message, [
156+
'[assert.near] not in delta /path/to/some_test.js',
157+
'assert.near(actualVal, expectedVal, delta, messageStr)',
158+
'[{"value":10.6,"espath":"arguments/0"},{"value":10,"espath":"arguments/1"},{"value":0.5,"espath":"arguments/2"}]: Expected 10.6 to be equal to 10 +/- 0.5'
159+
].join('\n'));
160+
}
161+
});
162+
});
163+
129164
}));

0 commit comments

Comments
 (0)