Skip to content

Commit a62bc01

Browse files
Fix expected value in InstanceOf assertion
1 parent 9604df7 commit a62bc01

File tree

3 files changed

+46
-29
lines changed

3 files changed

+46
-29
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xunit.ts",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "A unit testing framework for TypeScript, following standard xUnit patterns",
55
"main": "dist/xunit.js",
66
"author": "ecoAPM LLC",

src/Assertions/InstanceOf.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@ import { AssertionError } from "assert";
22

33
/**
44
* Asserts that a value is an instance of a certain type
5-
*
5+
*
66
* @remarks
77
* Passes if `object`'s type matches `type`
8-
*
9-
* Fails if `object`'s type does not match `type`
8+
*
9+
* Fails if `object`'s type does not match `type`
1010
*
1111
* @param type the expected type of the value
1212
* @param expression the value to check
1313
* @param message (optional) message to display on failure
14-
*
14+
*
1515
* @example
1616
* this.assert.instanceOf(type, object);
1717
*/
1818
export default function InstanceOf<T>(type: any, expression: any, message?: string) {
19-
if (expression instanceof type) {
20-
return;
21-
}
19+
if (expression instanceof type) {
20+
return;
21+
}
2222

23-
throw new AssertionError({
24-
message: message || `Expected expression of type, but was ${typeof expression}`,
25-
expected: type,
26-
actual: typeof expression
27-
})
23+
throw new AssertionError({
24+
message: message || `Expected expression of type, but was ${typeof expression}`,
25+
expected: type.name,
26+
actual: typeof expression
27+
})
2828
}

tests/Assertions/InstanceOfTests.ts

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,37 @@ export default class InstanceOfTests extends TestSuite {
1515
this.assert.true(true);
1616
}
1717

18-
@Test()
19-
async ThrowsWhenFalse() {
20-
//arrange
21-
const value = new class X { };
22-
23-
try {
24-
//act
25-
InstanceOf(TestSuite, value);
26-
throw new Error("Assertion failed");
27-
}
28-
catch (exception) {
29-
30-
//assert
31-
this.assert.instanceOf(AssertionError, exception);
32-
}
33-
}
18+
@Test()
19+
async ThrowsWhenFalse() {
20+
//arrange
21+
const value = new class X { };
22+
23+
try {
24+
//act
25+
InstanceOf(TestSuite, value);
26+
throw new Error("Assertion failed");
27+
}
28+
catch (exception) {
29+
30+
//assert
31+
this.assert.instanceOf(AssertionError, exception);
32+
}
33+
}
34+
35+
@Test()
36+
async ExpectedValueIsTypeName() {
37+
//arrange
38+
const value = new class X { };
39+
40+
try {
41+
//act
42+
InstanceOf(TestSuite, value);
43+
throw new Error("Assertion failed");
44+
}
45+
catch (exception) {
46+
47+
//assert
48+
this.assert.equal(TestSuite.name, (exception as AssertionError).expected);
49+
}
50+
}
3451
}

0 commit comments

Comments
 (0)