Skip to content

Commit f156dab

Browse files
committed
fix(matcher): Support undefined values.
1 parent fa42ce9 commit f156dab

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

fixtures/mocha/issues-spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @license Use of this source code is governed by an MIT-style license that
3+
* can be found in the LICENSE file at https://github.com/cartant/rxjs-marbles
4+
*/
5+
/*tslint:disable:object-literal-sort-keys*/
6+
7+
import { expect } from "chai";
8+
import { of } from "rxjs/observable/of";
9+
import { cases, marbles } from "../../dist/mocha";
10+
11+
describe("issues", () => {
12+
13+
describe("issue-22", () => {
14+
15+
it("should fail with a useful error message", marbles(m => {
16+
expect(() => {
17+
const actual = of([undefined]);
18+
m.expect(actual).toBeObservable("--|");
19+
m.autoFlush = false;
20+
m.flush();
21+
}).to.throw(/\{"frame":0,"notification":\{"kind":"N","value":"\[\s*undefined\s*\]","hasValue":true\}\}/);
22+
}));
23+
});
24+
});

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
"description": "An RxJS marble testing library for any test framework",
1111
"devDependencies": {
12+
"@types/chai": "^4.1.2",
1213
"@types/jasmine": "^2.5.53",
1314
"@types/jest": "^22.0.0",
1415
"@types/mocha": "^2.2.41",
@@ -18,6 +19,7 @@
1819
"babel-preset-es2015-rollup": "^3.0.0",
1920
"babel-preset-es2016": "^6.24.0",
2021
"babel-preset-es2017": "^6.24.0",
22+
"chai": "^4.1.2",
2123
"cpy-cli": "^1.0.1",
2224
"cross-env": "^5.0.5",
2325
"jasmine": "^2.6.0",

source/matcher.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import isEqual from "lodash-es/isEqual";
1919

2020
function stringify(x: any): string {
21+
if (x === undefined) {
22+
return 'undefined';
23+
}
2124
return JSON.stringify(x, function (key: any, value: any): any {
2225
if (Array.isArray(value)) {
2326
return '[' + value

yarn.lock

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
pretty-ms "^0.2.1"
6262
text-table "^0.2.0"
6363

64+
"@types/chai@^4.1.2":
65+
version "4.1.2"
66+
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.1.2.tgz#f1af664769cfb50af805431c407425ed619daa21"
67+
6468
"@types/jasmine@^2.5.53":
6569
version "2.8.6"
6670
resolved "https://registry.yarnpkg.com/@types/jasmine/-/jasmine-2.8.6.tgz#14445b6a1613cf4e05dd61c3c3256d0e95c0421e"
@@ -257,6 +261,10 @@ assert-plus@^0.2.0:
257261
version "0.2.0"
258262
resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-0.2.0.tgz#d74e1b87e7affc0db8aadb7021f3fe48101ab234"
259263

264+
assertion-error@^1.0.1:
265+
version "1.1.0"
266+
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b"
267+
260268
astral-regex@^1.0.0:
261269
version "1.0.0"
262270
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9"
@@ -1074,6 +1082,17 @@ center-align@^0.1.1:
10741082
align-text "^0.1.3"
10751083
lazy-cache "^1.0.3"
10761084

1085+
chai@^4.1.2:
1086+
version "4.1.2"
1087+
resolved "https://registry.yarnpkg.com/chai/-/chai-4.1.2.tgz#0f64584ba642f0f2ace2806279f4f06ca23ad73c"
1088+
dependencies:
1089+
assertion-error "^1.0.1"
1090+
check-error "^1.0.1"
1091+
deep-eql "^3.0.0"
1092+
get-func-name "^2.0.0"
1093+
pathval "^1.0.0"
1094+
type-detect "^4.0.0"
1095+
10771096
chalk@^0.4.0:
10781097
version "0.4.0"
10791098
resolved "https://registry.yarnpkg.com/chalk/-/chalk-0.4.0.tgz#5199a3ddcd0c1efe23bc08c1b027b06176e0c64f"
@@ -1100,6 +1119,10 @@ chalk@^2.0.0, chalk@^2.0.1, chalk@^2.3.0:
11001119
escape-string-regexp "^1.0.5"
11011120
supports-color "^4.0.0"
11021121

1122+
check-error@^1.0.1:
1123+
version "1.0.2"
1124+
resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82"
1125+
11031126
chokidar@^1.4.2:
11041127
version "1.7.0"
11051128
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468"
@@ -1393,6 +1416,12 @@ decamelize@^1.0.0, decamelize@^1.1.1, decamelize@^1.1.2:
13931416
version "1.2.0"
13941417
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
13951418

1419+
deep-eql@^3.0.0:
1420+
version "3.0.1"
1421+
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-3.0.1.tgz#dfc9404400ad1c8fe023e7da1df1c147c4b444df"
1422+
dependencies:
1423+
type-detect "^4.0.0"
1424+
13961425
deep-equal@^1.0.0, deep-equal@~1.0.1:
13971426
version "1.0.1"
13981427
resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-1.0.1.tgz#f5d260292b660e084eff4cdbc9f08ad3247448b5"
@@ -1805,6 +1834,10 @@ get-caller-file@^1.0.1:
18051834
version "1.0.2"
18061835
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.2.tgz#f702e63127e7e231c160a80c1554acb70d5047e5"
18071836

1837+
get-func-name@^2.0.0:
1838+
version "2.0.0"
1839+
resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41"
1840+
18081841
get-port@^3.0.0:
18091842
version "3.2.0"
18101843
resolved "https://registry.yarnpkg.com/get-port/-/get-port-3.2.0.tgz#dd7ce7de187c06c8bf353796ac71e099f0980ebc"
@@ -3379,6 +3412,10 @@ path-type@^2.0.0:
33793412
dependencies:
33803413
pify "^2.0.0"
33813414

3415+
pathval@^1.0.0:
3416+
version "1.1.0"
3417+
resolved "https://registry.yarnpkg.com/pathval/-/pathval-1.1.0.tgz#b942e6d4bde653005ef6b71361def8727d0645e0"
3418+
33823419
performance-now@^0.2.0:
33833420
version "0.2.0"
33843421
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-0.2.0.tgz#33ef30c5c77d4ea21c5a53869d91b56d8f2555e5"
@@ -4302,6 +4339,10 @@ type-check@~0.3.2:
43024339
dependencies:
43034340
prelude-ls "~1.1.2"
43044341

4342+
type-detect@^4.0.0:
4343+
version "4.0.8"
4344+
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
4345+
43054346
typescript@~2.7.1:
43064347
version "2.7.1"
43074348
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.1.tgz#bb3682c2c791ac90e7c6210b26478a8da085c359"

0 commit comments

Comments
 (0)