Skip to content

Commit

Permalink
fix(matcher): Support undefined values.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Feb 15, 2018
1 parent fa42ce9 commit f156dab
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
24 changes: 24 additions & 0 deletions fixtures/mocha/issues-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @license Use of this source code is governed by an MIT-style license that
* can be found in the LICENSE file at https://github.com/cartant/rxjs-marbles
*/
/*tslint:disable:object-literal-sort-keys*/

import { expect } from "chai";
import { of } from "rxjs/observable/of";
import { cases, marbles } from "../../dist/mocha";

describe("issues", () => {

describe("issue-22", () => {

it("should fail with a useful error message", marbles(m => {
expect(() => {
const actual = of([undefined]);
m.expect(actual).toBeObservable("--|");
m.autoFlush = false;
m.flush();
}).to.throw(/\{"frame":0,"notification":\{"kind":"N","value":"\[\s*undefined\s*\]","hasValue":true\}\}/);
}));
});
});
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"description": "An RxJS marble testing library for any test framework",
"devDependencies": {
"@types/chai": "^4.1.2",
"@types/jasmine": "^2.5.53",
"@types/jest": "^22.0.0",
"@types/mocha": "^2.2.41",
Expand All @@ -18,6 +19,7 @@
"babel-preset-es2015-rollup": "^3.0.0",
"babel-preset-es2016": "^6.24.0",
"babel-preset-es2017": "^6.24.0",
"chai": "^4.1.2",
"cpy-cli": "^1.0.1",
"cross-env": "^5.0.5",
"jasmine": "^2.6.0",
Expand Down
3 changes: 3 additions & 0 deletions source/matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import isEqual from "lodash-es/isEqual";

function stringify(x: any): string {
if (x === undefined) {
return 'undefined';
}
return JSON.stringify(x, function (key: any, value: any): any {
if (Array.isArray(value)) {
return '[' + value
Expand Down
41 changes: 41 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
pretty-ms "^0.2.1"
text-table "^0.2.0"

"@types/chai@^4.1.2":
version "4.1.2"
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.1.2.tgz#f1af664769cfb50af805431c407425ed619daa21"

"@types/jasmine@^2.5.53":
version "2.8.6"
resolved "https://registry.yarnpkg.com/@types/jasmine/-/jasmine-2.8.6.tgz#14445b6a1613cf4e05dd61c3c3256d0e95c0421e"
Expand Down Expand Up @@ -257,6 +261,10 @@ assert-plus@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-0.2.0.tgz#d74e1b87e7affc0db8aadb7021f3fe48101ab234"

assertion-error@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b"

astral-regex@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9"
Expand Down Expand Up @@ -1074,6 +1082,17 @@ center-align@^0.1.1:
align-text "^0.1.3"
lazy-cache "^1.0.3"

chai@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/chai/-/chai-4.1.2.tgz#0f64584ba642f0f2ace2806279f4f06ca23ad73c"
dependencies:
assertion-error "^1.0.1"
check-error "^1.0.1"
deep-eql "^3.0.0"
get-func-name "^2.0.0"
pathval "^1.0.0"
type-detect "^4.0.0"

chalk@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-0.4.0.tgz#5199a3ddcd0c1efe23bc08c1b027b06176e0c64f"
Expand All @@ -1100,6 +1119,10 @@ chalk@^2.0.0, chalk@^2.0.1, chalk@^2.3.0:
escape-string-regexp "^1.0.5"
supports-color "^4.0.0"

check-error@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82"

chokidar@^1.4.2:
version "1.7.0"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468"
Expand Down Expand Up @@ -1393,6 +1416,12 @@ decamelize@^1.0.0, decamelize@^1.1.1, decamelize@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"

deep-eql@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-3.0.1.tgz#dfc9404400ad1c8fe023e7da1df1c147c4b444df"
dependencies:
type-detect "^4.0.0"

deep-equal@^1.0.0, deep-equal@~1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-1.0.1.tgz#f5d260292b660e084eff4cdbc9f08ad3247448b5"
Expand Down Expand Up @@ -1805,6 +1834,10 @@ get-caller-file@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.2.tgz#f702e63127e7e231c160a80c1554acb70d5047e5"

get-func-name@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41"

get-port@^3.0.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/get-port/-/get-port-3.2.0.tgz#dd7ce7de187c06c8bf353796ac71e099f0980ebc"
Expand Down Expand Up @@ -3379,6 +3412,10 @@ path-type@^2.0.0:
dependencies:
pify "^2.0.0"

pathval@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/pathval/-/pathval-1.1.0.tgz#b942e6d4bde653005ef6b71361def8727d0645e0"

performance-now@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-0.2.0.tgz#33ef30c5c77d4ea21c5a53869d91b56d8f2555e5"
Expand Down Expand Up @@ -4302,6 +4339,10 @@ type-check@~0.3.2:
dependencies:
prelude-ls "~1.1.2"

type-detect@^4.0.0:
version "4.0.8"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"

typescript@~2.7.1:
version "2.7.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.1.tgz#bb3682c2c791ac90e7c6210b26478a8da085c359"
Expand Down

0 comments on commit f156dab

Please sign in to comment.