pax_global_header00006660000000000000000000000064130362502310014505gustar00rootroot0000000000000052 comment=de7202b0a70fea57e87431c9c5c22a1b3318f134 js-must-0.13.4/000077500000000000000000000000001303625023100131745ustar00rootroot00000000000000js-must-0.13.4/.editorconfig000066400000000000000000000001651303625023100156530ustar00rootroot00000000000000root = true [Makefile] indent_style = tab [*.js] indent_style = space indent_size = 2 [*.json] indent_style = tab js-must-0.13.4/.gitignore000066400000000000000000000000331303625023100151600ustar00rootroot00000000000000/node_modules/ /tmp/ *.tgz js-must-0.13.4/.mailmap000066400000000000000000000000331303625023100146110ustar00rootroot00000000000000Andri Möll js-must-0.13.4/.npmignore000066400000000000000000000000521303625023100151700ustar00rootroot00000000000000/*.tgz /tmp/ /.travis.yml /.mailmap /tags js-must-0.13.4/.travis.yml000066400000000000000000000002351303625023100153050ustar00rootroot00000000000000sudo: false language: node_js node_js: - "node" - "0.10" - "0.11" - "0.12" - "4" - "5" - "6" - "7" notifications: email: ["andri@dot.ee"] js-must-0.13.4/CHANGELOG.md000066400000000000000000000230041303625023100150040ustar00rootroot00000000000000## 0.13.4 (Jan 13, 2017) - Tweaks `Must.prototype.be` et al. implementation to prevent [`source-map-support`](https://github.com/evanw/node-source-map-support) from throwing an exception during call stack retrieval. This only happened if that module was used with Must.js for source map support. ## 0.13.3 (Jan 12, 2017) - Adds a first draft of TypeScript definitions. Thanks, [Karl Purkhardt][@KarlPurk]! - Serialize `NaN`s in objects in error messages as `"[NaN]"`. [@KarlPurk]: https://github.com/KarlPurk ## 0.13.2 (Jul 20, 2016) - Fixes stringifying `Symbol`s for assertion errors. - Stringifies `RegExp`s nested in objects for assertion errors. - Adds [`symbol`]. - Adds [`properties`]. - Adds [`ownProperties`]. - Adds preliminary support for running under strict mode (`"use strict"`). Assertion error stack traces will contain one Must.js function at the top at the moment. This will be fixed! [`symbol`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.symbol [`properties`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.properties [`ownProperties`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.ownProperties ## 0.13.1 (Sep 26, 2015) - Adds custom error message to [`Must`](https://github.com/moll/js-must/blob/master/doc/API.md#Must). ## 0.13.0 (Sep 26, 2015) - Lucky version. No changes since the previous release candidate. ## 0.13.0-rc1 (Sep 22, 2015) - Refactors [`eql`] to internally use [Egal.js](https://github.com/moll/js-egal), which was extracted from Must.js. Must.js augments `egal` to continue to allow you to assert equivalence to `NaN`s and instances of classes that aren't value objects. Egal.js doesn't compare those out of the box as they're not things you want to do in production code. With the transition to Egal.js, [`eql`] now also supports value objects that return compound values. See [Egal.js's README](https://github.com/moll/js-egal#value-objects) for details. ## 0.13.0-beta2 (Jun 15, 2015) - Fixes the stack trace when using promises with some particular matchers. ## 0.13.0-beta1 (Jun 15, 2015) - Adds [`must`] that returns self for those of us who sometimes write it twice: ```javascript demand(undefined).must.be.undefined() ``` - Fixes a false positive in [`eql`][] when an object had some keys set to `undefined`. - Adds [`the`] for a fluent chain. - Changes [`boolean`] to not consider boxed boolean objects as booleans. - Changes [`number`] to not consider boxed number objects as numbers. - Changes [`string`] to not consider boxed string objects as strings. - Changes [`true`] and [`false`] to not consider boxed boolean objects as either true or false. - Adds [`resolve`] and [`reject`] for asserting on promises. The former is also aliased to [`then`] and [`eventually`] for different language styles. With [Mocha](http://mochajs.org), using this will look something like: ```javascript it("must pass", function() { return Promise.resolve(42).must.resolve.to.equal(42) }) ``` Using [CoMocha](https://github.com/blakeembrey/co-mocha), it'll look like: ```javascript it("must pass", function*() { yield Promise.resolve(42).must.resolve.to.equal(42) yield Promise.resolve(42).must.then.equal(42) yield Promise.reject(42).must.reject.and.equal(42) }) ``` - Adds [`with`] for a fluent chain. - Adds [`error`] to assert on errors. Similar to [`throw`], but useful for when you already have an error at hand. - Adds [`startWith`]. - Adds [`endWith`]. - Adds [`nan`] to test `NaN`. [`must`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.must [`the`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.the [`boolean`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.boolean [`number`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.number [`string`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.string [`true`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.true [`false`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.false [`resolve`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.resolve [`reject`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.reject [`then`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.then [`with`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.with [`error`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.error [`startWith`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.startWith [`endWith`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.endWith [`nan`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.nan ## 0.12.0 (May 28, 2014) - Adds [`permutationOf`] to assert that two arrays contain the same elements. Thanks, [Miroslav Bajtoš][@bajtos]! [`permutationOf`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.permutationOf [@bajtos]: http://about.me/bajtos ## 0.11.0 (Feb 13, 2014) - Works on other JavaScript engines besides V8 by not assuming `Error.captureStackTrace`. Thanks, [Dmitry Starostin][@incrop]! [@incrop]: https://github.com/incrop ## 0.10.0 (Oct 31, 2013) - Allows asserting `NaN`s with [`eql`] — `NaN.must.eql(NaN)`. ## 0.9.1 (Oct 31, 2013) - Fixes [`eql`] to consider two equivalent boxed `Boolean`, `Number` or `String` values *eql*. Previously it only did so if both were primitive (`42`) or only one was boxed (`new Number(42)`). ## 0.9.0 (Oct 28, 2013) - Adds [`between`] to assert that a value is between a range. [`between`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.between ## 0.8.0 (Oct 27, 2013) - Allows asserting and comparing circular and self-referential objects with [`eql`]. Objects that are self-referential in the exact same way are considered *eql*. - Displays circular and self-referential objects and arrays in assertion error messages properly. - Displays object's inherited properties in assertion error messages. ## 0.7.0 (Oct 23, 2013) - Adds [`contain`] as an alias of [`include`]. - Adds [`before`] as an alias of [`below`] to make comparing dates read more natural: ```javascript new Date(2000, 5, 18).must.be.before(new Date(2001, 0, 1)) ``` - Adds [`after`] as an alias of [`above`] to make comparing dates read more natural: ```javascript new Date(2030, 5, 18).must.be.after(new Date(2013, 9, 23)) ``` [`contain`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.contain [`include`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.include [`below`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.below [`before`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.before [`above`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.above [`after`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.after ## 0.6.0 (Oct 15, 2013) - Allows asserting both the exception constructor and its message together in the [`throw`] matcher: ```javascript someFunction.must.throw(RangeError, /out of bounds/) ``` [`throw`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.throw ## 0.5.0 (Oct 13, 2013) - Sets the [`eql`] matcher's [`AssertionError`] diffable so some test runners would print out a property-by-property diff for mismatches. This helps visual comparison. [`AssertionError`]: https://github.com/moll/js-must/blob/master/doc/API.md#AssertionError ## 0.4.0 (Oct 11, 2013) - Changes [`eql`] so it also compares instances of the same class recursively like it does with plain objects. If the instance has a `valueOf` function, however, its output is used as before. [`eql`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.eql ## 0.3.0 (Oct 5, 2013) - Allows asserting [`property`] and [`ownProperty`] on all types (such as functions, booleans etc.), not only objects. - Allows asserting [`keys`] and [`ownKeys`] on all types (such as functions, booleans etc.), not only objects. - Allows asserting [`enumerable`] and [`nonenumerable`] properties on all types (such as functions, booleans etc.), not only objects. [`nonenumerable`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.nonenumerable [`ownProperty`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.ownProperty ## 0.2.0 (Sep 26, 2013) - Fails gracefully if property matchers ([`property`], [`enumerable`] etc.) are used on non-objects. - Adds the [`keys`] matcher to test if an object has all the expected keys. Takes inherited keys into account just like the [`empty`] and [`property`] matchers. - Adds the [`ownKeys`] matcher to test if an object has all the expected keys of its own. [`empty`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.empty [`enumerable`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.enumerable [`property`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.property [`keys`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.keys [`ownKeys`]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.ownKeys ## 0.1.338 (Sep 26, 2013) - Fixes Must.js's own tests on Windows thanks to [Bart van der Schoor][bartvds]. [bartvds]: https://github.com/Bartvds ## 0.1.337 (Sep 24, 2013) - First release. Must-have! js-must-0.13.4/LICENSE000066400000000000000000000016431303625023100142050ustar00rootroot00000000000000Must.js Copyright (C) 2013 Andri Möll This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. Additional permission under the GNU Affero GPL version 3 section 7: If you modify this Program, or any covered work, by linking or combining it with other code, such other code is not for that reason alone subject to any of the requirements of the GNU Affero GPL version 3. In summary: - You can use this program for no cost. - You can use this program for both personal and commercial reasons. - You do not have to share your own program's code which uses this program. - You have to share modifications (e.g bug-fixes) you've made to this program. For the full copy of the GNU Affero General Public License see: http://www.gnu.org/licenses. js-must-0.13.4/Makefile000066400000000000000000000026251303625023100146410ustar00rootroot00000000000000NODE = node NODE_OPTS = TEST_OPTS = MOCUMENT = ~/Documents/Mocumentation/bin/mocument MOCUMENT_OPTS = --type yui --title Must.js love: @echo "Feel like makin' love." test: @$(NODE) $(NODE_OPTS) ./node_modules/.bin/_mocha -R dot $(TEST_OPTS) spec: @$(NODE) $(NODE_OPTS) ./node_modules/.bin/_mocha -R spec $(TEST_OPTS) autotest: @$(NODE) $(NODE_OPTS) ./node_modules/.bin/_mocha -R dot --watch $(TEST_OPTS) autospec: @$(NODE) $(NODE_OPTS) ./node_modules/.bin/_mocha -R spec --watch $(TEST_OPTS) pack: @file=$$(npm pack); echo "$$file"; tar tf "$$file" publish: npm publish publish-beta: npm publish --tag beta # NOTE: Sorry, mocumentation is not yet published. doc: doc.json @mkdir -p doc @$(MOCUMENT) $(MOCUMENT_OPTS) \ --priority Must,Object \ tmp/doc/data.json > doc/API.md toc: doc.json @$(MOCUMENT) $(MOCUMENT_OPTS) \ --template toc \ --include Must \ --var api_url=https://github.com/moll/js-must/blob/master/doc/API.md \ tmp/doc/data.json > tmp/TOC.md @echo '/^API$$/,/^Migrating/{/^API$$/{r tmp/TOC.md\na\\\n\\\n\\\n\n};/^Migrating/!d;}' |\ sed -i "" -f /dev/stdin README.md doc.json: @mkdir -p tmp @yuidoc --exclude test,node_modules --parse-only --outdir tmp/doc . clean: rm -rf tmp *.tgz tag: git tag "v$$($(NODE) -e 'console.log(require("./package").version)')" .PHONY: love .PHONY: test spec autotest autospec .PHONY: pack publish clean .PHONY: doc toc doc.json .PHONY: tag js-must-0.13.4/README.md000066400000000000000000000477731303625023100144750ustar00rootroot00000000000000Must.js ======= [![NPM version][npm-badge]](https://www.npmjs.com/package/must) [![Build status][travis-badge]](https://travis-ci.org/moll/js-must) Must.js is a testing and assertion library for JavaScript and Node.js with a friendly **BDD** syntax (`awesome.must.be.true()`). It ships with **many expressive matchers** and is **test runner and framework agnostic**. Follows [RFC 2119][rfc2119] with its use of **MUST**. Good and well testsed stuff. For those new to testing JavaScript on Node.js, you'll also need a test framework (also called a test-runner or a harness) to run your tests. One such tool is [Mocha][mocha]. [npm-badge]: https://img.shields.io/npm/v/must.svg [travis-badge]: https://travis-ci.org/moll/js-must.png?branch=master [rfc2119]: https://www.ietf.org/rfc/rfc2119.txt [mocha]: https://mochajs.org ### Tour - Assert with a **beautiful and fluent chain** that saves you from wrapping objects manually and reads nicely, too: ```javascript require("must/register") obj.must.be.true() ``` - Supports the **expect flavor** of wrapping as well: ```javascript var demand = require("must") demand(obj).be.string() ``` - **Many expressive matchers** out of the box, including: ```javascript [].must.be.empty() obj.must.have.nonenumerable("foo") (42).must.be.above(13) ``` - **Simple**, because **matchers always behave the same way** and don't depend on any "special flags" in the chain. They are also **not interdependent** the way `foo.should.have.property(x).with.lengthOf(5)` would be. - **Reasonable**, because it asserts only when you call the matcher `[].must.be.empty()` and not when you merely get the property `empty`. See below why [asserting on property access](#asserting-on-property-access) is **dangerous** in other assertion libraries. - Has an **intelligent and type-safe** recursive [`eql`][Must.prototype.eql] matcher that compares arrays and objects by content and supports value objects. It's fully type-safe, so instances of *different classes* aren't *eql*, even if their properties are. It also supports **circular and self-referential** objects. ```javascript primesBelowTen.must.eql([2, 3, 5, 7]) model.attributes.must.eql({title: "New", createdAt: new Date(2000, 1, 1)}) ``` - Built-in support for **asserting on promises** with stack traces leading back to _your_ assertion, not to the library's internals. ```javascript Promise.resolve(42).must.then.equal(42) Promise.resolve([1, 2, 3]).must.eventually.not.include(42) Promise.reject(new Error("Problemo")).must.reject.with.error(/problem/i) ``` - **Human readable error messages** let you know if an object wasn't what you expected. You can also customize or prepend to the autogenerated error message for further clarification. - Honors [RFC 2119][rfc2119] by using the word **MUST** because your tests assert things, they don't list wishes or prayers, right? Exactly! `Foo.must.equal(42)`, not `foo.pretty.please.equal(42)`. - Works with any test runner and framework. - Avoids type coercions and mismatches. - Well tested — over 700 cases in over 2500 lines of tests. That makes a test to code ratio of 5:1. ### Using Should.js or Chai.js? Switch for safety! Among other things, one reason why [Should.js][should.js] and [Chai.js][chai.js] inspired me to write Must.js is that they have a **fundamental design mistake** that makes them both **surprising in a bad way** and **dangerous to use**. [Read more below](#asserting-on-property-access). ### Extensible Must.js features a very simple implementation and one you can extend yourself. In Must.js, every matcher is a function on `Must.prototype` that calls `Must.prototype.assert`. For now, please see the source of Must for examples. There are [plugins for Must.js](#plugins) by others available, too. Installing ---------- **Note**: Must.js will follow the [semantic versioning](http://semver.org/) starting from v1.0.0. ### Installing on Node.js ``` npm install must ``` ### Installing for the browser Must.js doesn't yet have a build ready for the browser, but you might be able to use [Browserify][browserify] to have it run there till then. [browserify]: https://github.com/substack/node-browserify Using ----- To use the **fluent chain**, just require Must.js's "register" file and it'll make itself available everywhere: ```javascript require("must/register") ``` Then just access the `must` property on any object and call matchers on it. ```javascript answer.must.equal(42) new Date().must.be.an.instanceof(Date) ``` If you wish to use the **expect flavor**, assign Must to any name of your choice, e.g: ```javascript var expect = require("must") var demand = require("must") ``` And call it with the object you wish to assert: ```javascript expect(answer).to.equal(42) demand(null).be.null() ``` For a list of all matchers, please see the [Must.js API Documentation][api]. ### Negative asserting or matching the opposite To assert the opposite, just add `not` between the chain: ```javascript true.must.not.be.false() [].must.not.be.empty() ``` Use it multiple times to create lots of fun puzzles! :-) ```javascript true.must.not.not.be.true() ``` ### Asserting on null and undefined values In almost all cases you can freely call methods on any object in JavaScript. Except for `null` and `undefined`. Most of the time this won't be a problem, because if you're asserting that `something.must.be.true()` and `something` ends up `null`, the test will still fail. If, however, you do need to assert its nullness, aliasing Must to `expect` or `demand` and wrapping it manually works well: ```javascript var demand = require("must") demand(something).be.null() demand(undefined).be.undefined() ``` If you've got an object on which a `null` or an `undefined` property must _exist_ in addition to having a nully value, use the [`property`][Must.prototype.property] matcher: ```javascript var obj = {id: null, name: undefined} obj.must.have.property("id", null) obj.must.have.property("name", undefined) ``` ### Autoloading If your test runner supports an options file, you might want to require Must there so you wouldn't have to remember to `require` in each test file. For [Mocha][mocha], that file is `test/mocha.opts`: ``` --require must/register ``` ### Full example Inside a test runner or framework things would look something like this: ```javascript require("must/register") var MySong = require("../my_song") describe("MySong", function() { it("must be creatable", function() { new MySong().must.be.an.instanceof(MySong) }) it("must have cowbell", function() { new MySong().cowbell.must.be.true() }) it("must not have pop", function() { new MySong().must.not.have.property("pop") }) }) ``` API --- For extended documentation on all functions, please see the [Must.js API Documentation][api]. [api]: https://github.com/moll/js-must/blob/master/doc/API.md ### [Must](https://github.com/moll/js-must/blob/master/doc/API.md#Must) - [.prototype.a](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.a)(class) - [.prototype.above](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.above)(expected) - [.prototype.after](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.after)(expected) - [.prototype.an](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.an)(class) - [.prototype.array](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.array)() - [.prototype.at](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.at) - [.prototype.be](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.be)(expected) - [.prototype.before](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.before)(expected) - [.prototype.below](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.below)(expected) - [.prototype.between](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.between)(begin, end) - [.prototype.boolean](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.boolean)() - [.prototype.contain](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.contain)(expected) - [.prototype.date](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.date)() - [.prototype.empty](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.empty)() - [.prototype.endWith](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.endWith)(expected) - [.prototype.enumerable](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.enumerable)(property) - [.prototype.enumerableProperty](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.enumerableProperty)(property) - [.prototype.eql](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.eql)(expected) - [.prototype.equal](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.equal)(expected) - [.prototype.error](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.error)([constructor], [expected]) - [.prototype.eventually](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.eventually) - [.prototype.exist](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.exist)() - [.prototype.false](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.false)() - [.prototype.falsy](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.falsy)() - [.prototype.frozen](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.frozen)() - [.prototype.function](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.function)() - [.prototype.gt](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.gt)(expected) - [.prototype.gte](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.gte)(expected) - [.prototype.have](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.have) - [.prototype.include](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.include)(expected) - [.prototype.instanceOf](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.instanceOf)(class) - [.prototype.instanceof](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.instanceof)(class) - [.prototype.is](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.is)(expected) - [.prototype.keys](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.keys)(keys) - [.prototype.least](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.least)(expected) - [.prototype.length](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.length)(expected) - [.prototype.lt](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.lt)(expected) - [.prototype.lte](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.lte)(expected) - [.prototype.match](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.match)(regexp) - [.prototype.most](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.most)(expected) - [.prototype.must](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.must) - [.prototype.nan](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.nan)() - [.prototype.nonenumerable](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.nonenumerable)(property) - [.prototype.nonenumerableProperty](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.nonenumerableProperty)(property) - [.prototype.not](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.not) - [.prototype.null](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.null)() - [.prototype.number](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.number)() - [.prototype.object](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.object)() - [.prototype.own](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.own)(property, [value]) - [.prototype.ownKeys](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.ownKeys)(keys) - [.prototype.ownProperties](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.ownProperties)(properties) - [.prototype.ownProperty](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.ownProperty)(property, [value]) - [.prototype.permutationOf](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.permutationOf)(expected) - [.prototype.properties](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.properties)(properties) - [.prototype.property](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.property)(property, [value]) - [.prototype.regexp](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.regexp)() - [.prototype.reject](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.reject) - [.prototype.resolve](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.resolve) - [.prototype.startWith](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.startWith)(expected) - [.prototype.string](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.string)() - [.prototype.symbol](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.symbol)() - [.prototype.the](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.the) - [.prototype.then](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.then) - [.prototype.throw](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.throw)([constructor], [expected]) - [.prototype.to](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.to) - [.prototype.true](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.true)() - [.prototype.truthy](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.truthy)() - [.prototype.undefined](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.undefined)() - [.prototype.with](https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.with) Migrating to Must.js -------------------- You're likely to be already using some testing library and have a set of tests in them. I'm **honored you picked** Must.js to go forward. Let's **get you up to speed** on how Must.js differs from others and how to **migrate your old tests** over. ### From Should.js Must.js and [Should.js][should.js] are fairly similar when it comes to matchers. - Just add parentheses after each assertion and you're almost set. - Must.js does not have static matchers like `should.not.exist(obj.foo)`. Convert to `demand(foo).not.to.exist()`. - Must.js lacks `with.lengthOf` because its matchers are all independent. Convert to `obj.must.have.length(5)` - Must.js lacks the `ok` matcher because unambiguous names are better. Convert to `truthy`. - Must.js does not support custom error descriptions. Here's a quick `sed` script to convert `obj.should.xxx` style to `obj.must.xxx()`: ``` sed -i.should -E -f /dev/stdin test/**/*.js <<-end /\.should\.([[:alpha:].]+)([[:space:]}\);]|$)/s/\.should\.([[:alpha:].]+)/.must.\1()/g s/\.should\.([[:alpha:].]+)/.must.\1/g end ``` ### From Chai.js Must.js and [Chai.js][chai.js] are fairly similar when it comes to matchers. - Just add parentheses after each assertion and you're almost set. That goes for both the BDD (`obj.should`) and *expect* (`expect(obj).to`) flavor. - Must.js lacks the `include` flag because its matchers are all independent. Convert to `Object.keys(obj).must.include("foo")`. - Must.js lacks the `deep` flag for the `equal` matcher because [`eql`][Must.prototype.eql] already compares recursively and in a type-safe way. Convert to `obj.must.eql({some: {deep: "object"}})`. - Must.js lacks the `deep` flag for the `property` matcher because it prefers regular property access. Convert to `obj.some.nested.property.must.equal(42)`. - Must.js lacks the `ok` matcher because unambiguous names are better. Convert to `truthy`. - Must.js lacks the `respondTo` matcher because unambiguous names are better. Convert to `MyClass.prototype.must.be.a.function()`. Here's a quick `sed` script to convert `obj.should.xxx` style to `obj.must.xxx()`: ``` sed -i.should -E -f /dev/stdin test/**/*.js <<-end /\.should\.([[:alpha:].]+)([[:space:]}\);]|$)/s/\.should\.([[:alpha:].]+)/.must.\1()/g s/\.should\.([[:alpha:].]+)/.must.\1/g end ``` ### Convert test case titles to MUST If you've used the `should` style before, you most likely have test cases titled `it("should do good")`. Migrate those to `it("must do good")` with this `sed` script: ``` sed -i.should -E -e 's/it\("should/it("must/g' test/**/*.js ``` ### Beware of libraries that assert on property access Among other things, one reason why [Should.js][should.js] and [Chai.js][chai.js] inspired me to write Must.js is that they have a **fundamental design mistake** that makes them both **surprising in a bad way** and **dangerous to use**. It has to do with them asserting on property access, like this: ```javascript true.should.be.true [].should.be.empty ``` What initially may seem familiar to Ruby programmers, first of all, is out of place in JavaScript. Dot-something stands for getting a property's value and getters, regardless of language, **should not** have **side-effects**. Especially not **control-flow changing exceptions**! Secondly, and this is where it's flat out **dangerous asserting on property access**, is that accessing a non-existent property does **nothing** in JavaScript. Recall that JavaScript does not have Ruby's `method_missing` or other hooks to catch such access. So, guess what happens when someone mistypes or mis-remembers a matcher? Yep, nothin' again. And that's the way it's supposed to be. But what's good in JavaScript, **not so good** for your now **false positive test**. Imagine using a plugin that adds matchers for spies or mocks. Then using it with `someFn.should.have.been.calledOnce`. Someone accidentally removes the plugin or thinks `calledQuadrice` sounds good? Well, those assertions will surely continue passing because they'll now just get `undefined` back. Must.js **solves both problems** with the **simplest but effective solution** — requires you to **always call matchers** because they're plain-old functions — `expect(problem).to.not.exist()`. [should.js]: https://github.com/visionmedia/should.js [chai.js]: http://chaijs.com Plugins ------- - [must-sinon](https://www.npmjs.com/package/must-sinon) ([Repository](https://github.com/JohnnyEstilles/must-sinon)) — Sinon assertions. - [must-targaryen](https://www.npmjs.com/package/must-targaryen) ([Repository](https://github.com/jtwebman/must-targaryen)) — Firebase Targaryen assertions. - [must-jsx](https://www.npmjs.com/package/must-jsx) ([Repository](https://github.com/nwinch/must-jsx)] — React.js JSX assertions. If you have a module extending Must.js one not listed above, please let me know or create a pull request. License ------- Must.js is released under a *Lesser GNU Affero General Public License*, which in summary means: - You **can** use this program for **no cost**. - You **can** use this program for **both personal and commercial reasons**. - You **do not have to share your own program's code** which uses this program. - You **have to share modifications** (e.g bug-fixes) you've made to this program. For more convoluted language, see the `LICENSE` file. About ----- **[Andri Möll](http://themoll.com)** typed this and the code. [Monday Calendar](https://mondayapp.com) supported the engineering work. If you find Must.js needs improving, please don't hesitate to type to me now at [andri@dot.ee][email] or [create an issue online][issues]. [email]: mailto:andri@dot.ee [issues]: https://github.com/moll/js-must/issues [Must.prototype.eql]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.eql [Must.prototype.property]: https://github.com/moll/js-must/blob/master/doc/API.md#Must.prototype.property js-must-0.13.4/doc/000077500000000000000000000000001303625023100137415ustar00rootroot00000000000000js-must-0.13.4/doc/API.md000066400000000000000000000722031303625023100147000ustar00rootroot00000000000000Must.js API Documentation ========================= ### [Must](#Must) - [.prototype.a](#Must.prototype.a)(class) - [.prototype.above](#Must.prototype.above)(expected) - [.prototype.after](#Must.prototype.after)(expected) - [.prototype.an](#Must.prototype.an)(class) - [.prototype.array](#Must.prototype.array)() - [.prototype.at](#Must.prototype.at) - [.prototype.be](#Must.prototype.be)(expected) - [.prototype.before](#Must.prototype.before)(expected) - [.prototype.below](#Must.prototype.below)(expected) - [.prototype.between](#Must.prototype.between)(begin, end) - [.prototype.boolean](#Must.prototype.boolean)() - [.prototype.contain](#Must.prototype.contain)(expected) - [.prototype.date](#Must.prototype.date)() - [.prototype.empty](#Must.prototype.empty)() - [.prototype.endWith](#Must.prototype.endWith)(expected) - [.prototype.enumerable](#Must.prototype.enumerable)(property) - [.prototype.enumerableProperty](#Must.prototype.enumerableProperty)(property) - [.prototype.eql](#Must.prototype.eql)(expected) - [.prototype.equal](#Must.prototype.equal)(expected) - [.prototype.error](#Must.prototype.error)([constructor], [expected]) - [.prototype.eventually](#Must.prototype.eventually) - [.prototype.exist](#Must.prototype.exist)() - [.prototype.false](#Must.prototype.false)() - [.prototype.falsy](#Must.prototype.falsy)() - [.prototype.frozen](#Must.prototype.frozen)() - [.prototype.function](#Must.prototype.function)() - [.prototype.gt](#Must.prototype.gt)(expected) - [.prototype.gte](#Must.prototype.gte)(expected) - [.prototype.have](#Must.prototype.have) - [.prototype.include](#Must.prototype.include)(expected) - [.prototype.instanceOf](#Must.prototype.instanceOf)(class) - [.prototype.instanceof](#Must.prototype.instanceof)(class) - [.prototype.is](#Must.prototype.is)(expected) - [.prototype.keys](#Must.prototype.keys)(keys) - [.prototype.least](#Must.prototype.least)(expected) - [.prototype.length](#Must.prototype.length)(expected) - [.prototype.lt](#Must.prototype.lt)(expected) - [.prototype.lte](#Must.prototype.lte)(expected) - [.prototype.match](#Must.prototype.match)(regexp) - [.prototype.most](#Must.prototype.most)(expected) - [.prototype.must](#Must.prototype.must) - [.prototype.nan](#Must.prototype.nan)() - [.prototype.nonenumerable](#Must.prototype.nonenumerable)(property) - [.prototype.nonenumerableProperty](#Must.prototype.nonenumerableProperty)(property) - [.prototype.not](#Must.prototype.not) - [.prototype.null](#Must.prototype.null)() - [.prototype.number](#Must.prototype.number)() - [.prototype.object](#Must.prototype.object)() - [.prototype.own](#Must.prototype.own)(property, [value]) - [.prototype.ownKeys](#Must.prototype.ownKeys)(keys) - [.prototype.ownProperties](#Must.prototype.ownProperties)(properties) - [.prototype.ownProperty](#Must.prototype.ownProperty)(property, [value]) - [.prototype.permutationOf](#Must.prototype.permutationOf)(expected) - [.prototype.properties](#Must.prototype.properties)(properties) - [.prototype.property](#Must.prototype.property)(property, [value]) - [.prototype.regexp](#Must.prototype.regexp)() - [.prototype.reject](#Must.prototype.reject) - [.prototype.resolve](#Must.prototype.resolve) - [.prototype.startWith](#Must.prototype.startWith)(expected) - [.prototype.string](#Must.prototype.string)() - [.prototype.symbol](#Must.prototype.symbol)() - [.prototype.the](#Must.prototype.the) - [.prototype.then](#Must.prototype.then) - [.prototype.throw](#Must.prototype.throw)([constructor], [expected]) - [.prototype.to](#Must.prototype.to) - [.prototype.true](#Must.prototype.true)() - [.prototype.truthy](#Must.prototype.truthy)() - [.prototype.undefined](#Must.prototype.undefined)() - [.prototype.with](#Must.prototype.with) ### [Object](#Object) - [.prototype.must](#Object.prototype.must) ### [AssertionError](#AssertionError) - [actual](#assertionError.actual) - [diffable](#assertionError.diffable) - [expected](#assertionError.expected) - [showDiff](#assertionError.showDiff) - [stack](#assertionError.stack) Must(actual, [message]) ----------------------- The main class that wraps the asserted object and that you call matchers on. To include a custom error message for failure cases, pass a string as the second argument. Most of the time you'll be using [`Object.prototype.must`](#Object.prototype.must) to create this wrapper, but occasionally you might want to assert `null`s or `undefined`s and in those cases assigning `Must` to something like `expect` or `demand` works nicely. **Examples**: ```javascript true.must.be.true() [].must.be.empty() var expect = require("must") expect(null).to.be.null() var demand = require("must") demand(undefined, "The undefined undefineds").be.undefined() ``` ### Must.prototype.a(class) Alias of [`instanceof`](#Must.prototype.instanceof). Can also be used a pass-through property for a fluent chain. **Examples**: ```javascript "Hello".must.be.a.string() new Date().must.be.a(Date) ``` ### Must.prototype.above(expected) Assert that an object is above and greater than (`>`) `expected`. Uses `>` for comparison, so it'll also work with value objects (those implementing [`valueOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)) like `Date`. **Examples**: ```javascript (69).must.be.above(42) ``` ### Must.prototype.after(expected) Alias of [`above`](#Must.prototype.above). Works well with dates where saying *after* is more natural than *above* or *greater than*. To assert that a date is equivalent to another date, use [`eql`](#Must.prototype.eql). For regular numbers, [`equal`](#Must.prototype.equal) is fine. **Examples**: ```javascript (1337).must.be.after(42) new Date(2030, 5, 18).must.be.after(new Date(2013, 9, 23)) ``` ### Must.prototype.an(class) Alias of [`instanceof`](#Must.prototype.instanceof). Can also be used a pass-through property for a fluent chain. **Examples**: ```javascript [1, 2].must.be.an.array() new AwesomeClass().must.be.an(AwesomeClass) ``` ### Must.prototype.array() Assert object is an array. **Examples**: ```javascript [42, 69].must.be.an.array() ``` ### Must.prototype.at Pass-through property for a fluent chain. **Examples**: ```javascript (42).must.be.at.most(69) (1337).must.be.at.least(1337) ``` ### Must.prototype.be(expected) Alias of [`equal`](#Must.prototype.equal). Can also be used as a pass-through property for a fluent chain. **Examples**: ```javascript true.must.be.true() (42).must.be(42) ``` ### Must.prototype.before(expected) Alias of [`below`](#Must.prototype.below). Works well with dates where saying *before* is more natural than *below* or *less than*. To assert that a date is equivalent to another date, use [`eql`](#Must.prototype.eql). For regular numbers, [`equal`](#Must.prototype.equal) is fine. **Examples**: ```javascript (42).must.be.before(1337) new Date(2000, 5, 18).must.be.before(new Date(2001, 0, 1)) ``` ### Must.prototype.below(expected) Assert that an object is below and less than (`<`) `expected`. Uses `<` for comparison, so it'll also work with value objects (those implementing [`valueOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)) like `Date`. **Examples**: ```javascript (42).must.be.below(69) ``` ### Must.prototype.between(begin, end) Assert that an object is between `begin` and `end` (inclusive). Uses `<` for comparison, so it'll also work with value objects (those implementing [`valueOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)) like `Date`. **Examples**: ```javascript (13).must.be.between(13, 69) (42).must.be.between(13, 69) (69).must.be.between(13, 69) ``` ### Must.prototype.boolean() Assert object is a boolean (`true` or `false`). Boxed boolean objects (`new Boolean`) are _not_ considered booleans. **Examples**: ```javascript true.must.be.a.boolean() ``` ### Must.prototype.contain(expected) Alias of [`include`](#Must.prototype.include). ### Must.prototype.date() Assert object is a date. **Examples**: ```javascript new Date().must.be.a.date() ``` ### Must.prototype.empty() Assert that an object is empty. Checks either the `length` for arrays and strings or the count of enumerable keys. Inherited keys also counted. **Examples**: ```javascript "".must.be.empty() [].must.be.empty() ({}).must.be.empty() ``` ### Must.prototype.endWith(expected) Assert a string ends with the given string. **Examples**: ```javascript "Hello, John".must.endWith("John") ``` ### Must.prototype.enumerable(property) Assert that an object has an enumerable property `property`. It will fail if the object lacks the property entirely. This also checks inherited properties in the prototype chain, something which `Object.prototype.propertyIsEnumerable` itself does not do. For checking if a property exists *and* is non-enumerable, see [`nonenumerable`](#Must.prototype.nonenumerable). **Examples**: ```javascript ({life: 42, love: 69}).must.have.enumerable("love") ``` ### Must.prototype.enumerableProperty(property) Alias of [`enumerable`](#Must.prototype.enumerable). ### Must.prototype.eql(expected) Assert object equality by content and if possible, recursively. Also handles circular and self-referential objects. For most parts it asserts strict equality (`===`), but: - `RegExp` objects are compared by their pattern and flags. - `Date` objects are compared by their value. - `Array` objects are compared recursively. - `NaN`s are considered equivalent. - Instances of the same class with a `valueOf` function are compared by its output. - Plain objects and instances of the same class are compared recursively. **Does not coerce types** so **mismatching types fail**. Inherited enumerable properties are also taken into account. **Instances** are objects whose prototype's `constructor` property is set. E.g. `new MyClass`. Others, like `{}` or `Object.create({})`, are **plain objects**. **Examples**: ```javascript /[a-z]/.must.eql(/[a-z]/) new Date(1987, 5, 18).must.eql(new Date(1987, 5, 18)) ["Lisp", 42].must.eql(["Lisp", 42]) ({life: 42, love: 69}).must.eql({life: 42, love: 69}) NaN.must.eql(NaN) function Answer(answer) { this.answer = answer } new Answer(42).must.eql(new Answer(42)) ``` ### Must.prototype.equal(expected) Assert object strict equality or identity (`===`). To compare value objects (like `Date` or `RegExp`) by their value rather than identity, use [`eql`](#Must.prototype.eql). To compare arrays and objects by content, also use [`eql`](#Must.prototype.eql). **Examples**: ```javascript (42).must.equal(42) var date = new Date date.must.equal(date) ``` ### Must.prototype.error([constructor], [expected]) Assert that an object is an error (instance of `Error` by default). Optionally assert it matches `expected` (and/or is of instance `constructor`). When you have a function that's supposed to throw, use [`throw`](#Must.prototype.throw). Given `expected`, the error is asserted as follows: - A **string** is compared with the exception's `message` property. - A **regular expression** is matched against the exception's `message` property. - A **function** (a.k.a. constructor) is used to check if the error is an `instanceof` that constructor. - All other cases of `expected` are left unspecified for now. **Examples**: ```javascript var err = throw new RangeError("Everything's amazing and nobody's happy") } err.must.be.an.error() err.must.be.an.error("Everything's amazing and nobody's happy") err.must.be.an.error(/amazing/) err.must.be.an.error(Error) err.must.be.an.error(RangeError) err.must.be.an.error(RangeError, "Everything's amazing and nobody's happy") err.must.be.an.error(RangeError, /amazing/) ``` ### Must.prototype.eventually Alias of [`resolve`](#Must.prototype.resolve). **Examples**: ```javascript Promise.resolve(42).must.eventually.equal(42) ``` ### Must.prototype.exist() Assert object is exists and thereby is not null or undefined. **Examples**: ```javascript 0.must.exist() "".must.exist() ({}).must.exist() ``` ### Must.prototype.false() Assert object is `false`. A boxed boolean object (`new Boolean(false`) is _not_ considered false. **Examples**: ```javascript false.must.be.false() ``` ### Must.prototype.falsy() Assert object is falsy (`!obj`). Only `null`, `undefined`, `0`, `false` and `""` are falsy in JavaScript. Everything else is truthy. **Examples**: ```javascript 0.must.be.falsy() "".must.be.falsy() ``` ### Must.prototype.frozen() Assert that an object is frozen with `Object.isFrozen`. **Examples**: ```javascript Object.freeze({}).must.be.frozen() ``` ### Must.prototype.function() Assert object is a function. **Examples**: ```javascript (function() {}).must.be.a.function() ``` ### Must.prototype.gt(expected) Alias of [`above`](#Must.prototype.above). ### Must.prototype.gte(expected) Alias of [`least`](#Must.prototype.least). ### Must.prototype.have Pass-through property for a fluent chain. **Examples**: ```javascript [1, 2].must.have.length(2) ``` ### Must.prototype.include(expected) Assert object includes `expected`. For strings it checks the text, for arrays it checks elements and for objects the property values. Everything is checked with strict equals (`===`). **Examples**: ```javascript "Hello, John!".must.include("John") [1, 42, 3].must.include(42) ({life: 42, love: 69}).must.include(42) ``` ### Must.prototype.instanceOf(class) Alias of [`instanceof`](#Must.prototype.instanceof). ### Must.prototype.instanceof(class) Assert that an object is an instance of something. Uses `obj instanceof expected`. **Examples**: ```javascript new Date().must.be.an.instanceof(Date) ``` ### Must.prototype.is(expected) Alias of [`equal`](#Must.prototype.equal). Can also be used as a pass-through property for a fluent chain. **Examples**: ```javascript var claim = require("must") claim(true).is.true() claim(42).is(42) ``` ### Must.prototype.keys(keys) Assert that an object has only the expected enumerable `keys`. Pass an array of strings as `keys`. Takes **inherited properties** into account. To not do so, see [`ownKeys`](#Must.prototype.ownKeys). **Examples**: ```javascript ({life: 42, love: 69}).must.have.keys(["life", "love"]) Object.create({life: 42}).must.have.keys(["life"]) ``` ### Must.prototype.least(expected) Assert that an object is at least, greater than or equal to (`>=`), `expected`. Uses `>=` for comparison, so it'll also work with value objects (those implementing [`valueOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)) like `Date`. **Examples**: ```javascript (69).must.be.at.least(42) (42).must.be.at.least(42) ``` ### Must.prototype.length(expected) Assert that an object has a length property equal to `expected`. **Examples**: ```javascript "Something or other".must.have.length(18) [1, 2, 3, "Four o'clock rock"].must.have.length(4) ``` ### Must.prototype.lt(expected) Alias of [`below`](#Must.prototype.below). ### Must.prototype.lte(expected) Alias of [`most`](#Must.prototype.most). ### Must.prototype.match(regexp) Assert object matches the given regular expression. If you pass in a non regular expression object, it'll be converted to one via `new RegExp(regexp)`. **Examples**: ```javascript "Hello, John!".must.match(/john/i) "Wei wu wei".must.match("wu") ``` ### Must.prototype.most(expected) Assert that an object is at most, less than or equal to (`<=`), `expected`. Uses `<=` for comparison, so it'll also work with value objects (those implementing [`valueOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)) like `Date`. **Examples**: ```javascript (42).must.be.at.most(69) (42).must.be.at.most(42) ``` ### Must.prototype.must Pass-through property for a fluent chain. **Examples**: ```javascript (42).must.must.must.must.equal(42) ``` ### Must.prototype.nan() Assert object is `NaN`. **Examples**: ```javascript NaN.must.be.nan() ``` ### Must.prototype.nonenumerable(property) Assert that an object has a non-enumerable property `property`. It will fail if the object lacks the property entirely. This also checks inherited properties in the prototype chain, something which `Object.prototype.propertyIsEnumerable` itself does not do. It's the inverse of [`enumerable`](#Must.prototype.enumerable). **Examples**: ```javascript (function() {}).must.have.nonenumerable("call") Object.create({}, {love: {enumerable: 0}}).must.have.nonenumerable("love") ``` ### Must.prototype.nonenumerableProperty(property) Alias of [`nonenumerable`](#Must.prototype.nonenumerable). ### Must.prototype.not Inverse the assertion. Use it multiple times to create lots of fun! `true.must.not.not.be.true()` :-) **Examples**: ```javascript true.must.not.be.true() [].must.not.be.empty() ``` ### Must.prototype.null() Assert object is `null`. Because JavaScript does not allow method calls on `null`, you'll have to wrap an expected null with [`Must`](#Must). Assigning `require("must")` to `expect` or `demand` works well. If you want to assert that an object's property is `null`, see [`property`](#Must.prototype.property). **Examples**: ```javascript var demand = require("must") demand(null).be.null() ``` ### Must.prototype.number() Assert object is a number. Boxed number objects (`new Number`) are _not_ considered numbers. **Examples**: ```javascript (42).must.be.a.number() ``` ### Must.prototype.object() Assert object is an.. object. **Examples**: ```javascript ({}).must.be.an.object() ``` ### Must.prototype.own(property, [value]) Alias of [`ownProperty`](#Must.prototype.ownProperty). ### Must.prototype.ownKeys(keys) Assert that an object has only the expected enumerable `keys` of its own. Pass an array of strings as `keys`. **Does not** take **inherited properties** into account. To do so, see [`keys`](#Must.prototype.keys). **Examples**: ```javascript ({life: 42, love: 69}).must.have.ownKeys(["life", "love"]) ``` ### Must.prototype.ownProperties(properties) Assert that an object has all of the properties given in `properties` with equal (`===`) values and that they're own properties. In other words, asserts that the given object is a subset of the one asserted against. **Does not** take **inherited properties** into account. To do so, see [`properties`](#Must.prototype.properties). **Examples**: ```javascript var john = {name: "John", age: 42, sex: "male"} john.must.have.ownProperties({name: "John", sex: "male"}) ``` ### Must.prototype.ownProperty(property, [value]) Assert that an object has own property `property`. Optionally assert it *equals* (`===`) to `value`. **Does not** take **inherited properties** into account. To do so, see [`property`](#Must.prototype.property). **Examples**: ```javascript ({life: 42, love: 69}).must.have.ownProperty("love", 69) ``` ### Must.prototype.permutationOf(expected) Assert that an array is a permutation of the given array. An array is a permutation of another if they both have the same elements (including the same number of duplicates) regardless of their order. Elements are checked with strict equals (`===`). **Examples**: ```javascript [1, 1, 2, 3].must.be.a.permutationOf([3, 2, 1, 1]) [7, 8, 8, 9].must.not.be.a.permutationOf([9, 8, 7]) ``` ### Must.prototype.properties(properties) Assert that an object has all of the properties given in `properties` with equal (`===`) values. In other words, asserts that the given object is a subset of the one asserted against. Takes **inherited properties** into account. To not do so, see [`ownProperties`](#Must.prototype.ownProperties). **Examples**: ```javascript var john = {name: "John", age: 42, sex: "male"} john.must.have.properties({name: "John", sex: "male"}) ``` ### Must.prototype.property(property, [value]) Assert that an object has property `property`. Optionally assert it *equals* (`===`) to `value`. Takes **inherited properties** into account. To not do so, see [`ownProperty`](#Must.prototype.ownProperty). **Examples**: ```javascript (function() {}).must.have.property("call") ({life: 42, love: 69}).must.have.property("love", 69) ``` ### Must.prototype.regexp() Assert object is a regular expression. **Examples**: ```javascript /[a-z]/.must.be.a.regexp() ``` ### Must.prototype.reject Makes any matcher following the use of `reject` wait till a promise is rejected before asserting. Returns a new promise that will either resolve if the assertion passed or fail with `AssertionError`. Promises are transparent to matchers, so everything will also work with customer matchers you've added to `Must.prototype`. Internally Must just waits on the promise and calls the matcher function once it's rejected. With [Mocha](http://mochajs.org), using this will look something like: ```javascript it("must pass", function() { return Promise.reject(42).must.reject.to.equal(42) }) ``` Using [CoMocha](https://github.com/blakeembrey/co-mocha), it'll look like: ```javascript it("must pass", function*() { yield Promise.reject(42).must.reject.to.equal(42) yield Promise.reject([1, 2, 3]).must.reject.to.not.include(42) }) ``` **Examples**: ```javascript Promise.reject(42).must.reject.to.equal(42) Promise.reject([1, 2, 3]).must.reject.to.not.include(42) ``` ### Must.prototype.resolve Makes any matcher following the use of `resolve` wait till a promise resolves before asserting. Returns a new promise that will either resolve if the assertion passed or fail with `AssertionError`. Promises are transparent to matchers, so everything will also work with customer matchers you've added to `Must.prototype`. Internally Must just waits on the promise and calls the matcher function once it's resolved. With [Mocha](http://mochajs.org), using this will look something like: ```javascript it("must pass", function() { return Promise.resolve(42).must.resolve.to.equal(42) }) ``` Using [CoMocha](https://github.com/blakeembrey/co-mocha), it'll look like: ```javascript it("must pass", function*() { yield Promise.resolve(42).must.resolve.to.equal(42) yield Promise.resolve([1, 2, 3]).must.resolve.to.not.include(42) }) ``` **Examples**: ```javascript Promise.resolve(42).must.resolve.to.equal(42) Promise.resolve([1, 2, 3]).must.resolve.to.not.include(42) ``` ### Must.prototype.startWith(expected) Assert a string starts with the given string. **Examples**: ```javascript "Hello, John".must.startWith("Hello") ``` ### Must.prototype.string() Assert object is a string. Boxed string objects (`new String`) are _not_ considered strings. **Examples**: ```javascript "Hello".must.be.a.string() ``` ### Must.prototype.symbol() Assert object is a symbol. **Examples**: ```javascript Symbol().must.be.a.symbol() ``` ### Must.prototype.the Pass-through property for a fluent chain. **Examples**: ```javascript (42).must.be.the.number() ``` ### Must.prototype.then Alias of [`resolve`](#Must.prototype.resolve). **Examples**: ```javascript Promise.resolve(42).must.then.equal(42) ``` ### Must.prototype.throw([constructor], [expected]) Assert that a function throws. Optionally assert it throws `expected` (and/or is of instance `constructor`). When you already have an error reference, use [`error`](#Must.prototype.error). Given `expected`, the error is asserted as follows: - A **string** is compared with the exception's `message` property. - A **regular expression** is matched against the exception's `message` property. - A **function** (a.k.a. constructor) is used to check if the error is an `instanceof` that constructor. - All other cases of `expected` are left unspecified for now. Because of how JavaScript works, the function will be called in `null` context (`this`). If you want to test an instance method, bind it: `obj.method.bind(obj).must.throw()`. **Examples**: ```javascript function omg() { throw new RangeError("Everything's amazing and nobody's happy") } omg.must.throw() omg.must.throw("Everything's amazing and nobody's happy") omg.must.throw(/amazing/) omg.must.throw(Error) omg.must.throw(RangeError) omg.must.throw(RangeError, "Everything's amazing and nobody's happy") omg.must.throw(RangeError, /amazing/) ``` ### Must.prototype.to Pass-through property for a fluent chain. **Examples**: ```javascript var expect = require("must") expect(true).to.be.true() var wish = require("must") wish(life).to.be.truthy() ``` ### Must.prototype.true() Assert object is `true`. A boxed boolean object (`new Boolean(true`) is _not_ considered true. **Examples**: ```javascript true.must.be.true() ``` ### Must.prototype.truthy() Assert object is truthy (`!!obj`). Only `null`, `undefined`, `0`, `false` and `""` are falsy in JavaScript. Everything else is truthy. **Examples**: ```javascript (42).must.be.truthy() "Hello".must.be.truthy() ``` ### Must.prototype.undefined() Assert object is `undefined`. Because JavaScript does not allow method calls on `undefined`, you'll have to wrap an expected undefined with [`Must`](#Must). Assigning `require("must")` to `expect` or `demand` works well. If you want to assert that an object's property is `undefined`, see [`property`](#Must.prototype.property). **Examples**: ```javascript var demand = require("must") demand(undefined).be.undefined() ``` ### Must.prototype.with Pass-through property for a fluent chain. **Examples**: ```javascript Promise.resolve(42).must.resolve.with.number() ``` Object ------ ### Object.prototype.must Creates an instance of [`Must`](#Must) with the current object for asserting and calling matchers on. This property is non-enumerable just like built-in properties, so it'll never interfere with any regular usage of objects. Please note that JavaScript does not allow method calls on `null` or `undefined`, so you'll sometimes have to call [`Must`](#Must) on them by hand. Assigning `require("must")` to `expect` or `demand` works well with those cases. **Examples**: ```javascript true.must.be.true() [].must.be.empty() ``` AssertionError(message, [options]) ---------------------------------- Error object thrown when an assertion fails. ### assertionError.actual The asserted object. ### assertionError.diffable Whether it makes sense to compare objects granularly or even show a diff view of the objects involved. Most matchers (e.g. [`empty`](#Must.prototype.empty) and [`string`](#Must.prototype.string)) are concrete, strict and atomic and don't lend themselves to be compared property by property. Others however, like [`eql`](#Must.prototype.eql), are more granular and comparing them line by line helps understand how they differ. ### assertionError.expected If the matcher took an argument or asserted against something (like `foo.must.be.true()`), then this is the expected value. ### assertionError.showDiff Alias of [`diffable`](#assertionError.diffable). Some test runners (like [Mocha](http://visionmedia.github.io/mocha/)) expect this property instead. ### assertionError.stack The stack trace starting from the code that called `must`. js-must-0.13.4/lib/000077500000000000000000000000001303625023100137425ustar00rootroot00000000000000js-must-0.13.4/lib/assertion_error.js000066400000000000000000000037711303625023100175300ustar00rootroot00000000000000var O = require("oolong") var FIRST_LINE = /^.*$/m module.exports = AssertionError /** * Error object thrown when an assertion fails. * * @class AssertionError * @constructor * @param message * @param [options] */ function AssertionError(msg, opts) { this.message = msg /** * The asserted object. * * @property actual */ if (opts && "actual" in opts) this.actual = opts.actual /** * If the matcher took an argument or asserted against something (like * `foo.must.be.true()`), then this is the expected value. * * @property expected */ if (opts && "expected" in opts) this.expected = opts.expected /** * Whether it makes sense to compare objects granularly or even show a diff * view of the objects involved. * * Most matchers (e.g. [`empty`](#Must.prototype.empty) and * [`string`](#Must.prototype.string)) are concrete, strict and atomic and * don't lend themselves to be compared property by property. Others however, * like [`eql`](#Must.prototype.eql), are more granular and comparing them * line by line helps understand how they differ. * * @property diffable */ if (opts && "diffable" in opts) this.diffable = opts.diffable /** * The stack trace starting from the code that called `must`. * * @property stack */ if (opts && opts.stack != null) Object.defineProperty(this, "stack", { value: opts.stack.replace(FIRST_LINE, this), configurable: true, writable: true }) else if (Error.captureStackTrace) Error.captureStackTrace(this, opts && opts.caller || this.constructor) } AssertionError.prototype = Object.create(Error.prototype, { constructor: {value: AssertionError, configurable: true, writable: true} }) AssertionError.prototype.name = "AssertionError" /** * Some test runners (like [Mocha](http://visionmedia.github.io/mocha/)) expect * this property instead. * * @property showDiff * @alias diffable */ O.defineGetter(AssertionError.prototype, "showDiff", function() { return this.diffable }) js-must-0.13.4/lib/es6.js000066400000000000000000000010261303625023100147740ustar00rootroot00000000000000exports.setPrototypeOf = Object.setPrototypeOf || function(obj, prototype) { /* eslint no-proto: 0 */ obj.__proto__ = prototype return obj } exports.startsWith = String.prototype.startsWith ? Function.call.bind(String.prototype.startsWith) : function(haystack, needle) { return haystack.lastIndexOf(needle, 0) === 0 } exports.endsWith = String.prototype.endsWith ? Function.call.bind(String.prototype.endsWith) : function(haystack, needle) { return haystack.indexOf(needle, haystack.length - needle.length) >= 0 } js-must-0.13.4/lib/index.js000066400000000000000000000034511303625023100154120ustar00rootroot00000000000000var kindof = require("kindof") var jsonify = require("json-stringify-safe") var setPrototypeOf = require("./es6").setPrototypeOf var INDENT = null exports.chain = function(self, fn) { if (typeof fn != "function") throw new TypeError("Not a function: " + fn) // Don't set toString as it seems to break "source-map-support". This is // a function with an Object prototype, after all. return Object.defineProperties(setPrototypeOf(fn.bind(self), self), { bind: {value: Function.prototype.apply, configurable: true, writable: true}, call: {value: Function.prototype.apply, configurable: true, writable: true}, apply: {value: Function.prototype.apply, configurable: true, writable: true} }) } exports.stringify = function stringify(obj) { var root = obj switch (kindof(obj)) { // Allow falling through: /* jshint -W086 */ /* eslint no-fallthrough: 0 */ case "null": return "null" case "undefined": return "undefined" case "number": return obj.toString() case "string": return JSON.stringify(obj) case "symbol": return obj.toString() case "regexp": return obj.toString() case "date": return obj.toISOString() case "function": return obj.toString() case "object": obj = clone(obj) if (root instanceof Error) obj.message = root.message // Fall through. default: return jsonify(obj, stringifyValue, INDENT) } } function clone(obj) { var clone = {}, value for (var key in obj) clone[key] = (value = obj[key]) === obj ? clone : value return clone } function stringifyValue(key, value) { switch (kindof(value)) { case "undefined": return "[Undefined]" case "number": return isNaN(value) ? "[NaN]" : value case "symbol": return value.toString() case "regexp": return value.toString() default: return value } } js-must-0.13.4/lib/rejectable.js000066400000000000000000000007511303625023100164030ustar00rootroot00000000000000var AssertionError = require("./assertion_error") var Thenable = require("./thenable") var then = Thenable.prototype.then module.exports = function(must) { return Thenable(must, promisify) } function promisify(fn) { return function matcher() { var must = Object.create(this) if (Error.captureStackTrace) Error.captureStackTrace(must, matcher) return this.actual.then(raise, then.bind(must, fn, arguments)) } } function raise() { throw new AssertionError("Resolved") } js-must-0.13.4/lib/resolvable.js000066400000000000000000000005451303625023100164420ustar00rootroot00000000000000var Thenable = require("./thenable") module.exports = function(must) { return Thenable(must, promisify) } function promisify(fn) { return function matcher() { var must = Object.create(this) if (Error.captureStackTrace) Error.captureStackTrace(must, matcher) return this.actual.then(Thenable.prototype.then.bind(must, fn, arguments)) } } js-must-0.13.4/lib/thenable.js000066400000000000000000000014651303625023100160700ustar00rootroot00000000000000var wrap = require("lodash.wrap") var lookupGetter = require("oolong").lookupGetter exports = module.exports = function(must, promisify) { must = Object.create(must) for (var name in must) if (hasFunction(must, name)) must[name] = promisify(must[name]) Object.defineProperty(must, "assert", { value: wrap(must.assert, exports.prototype.assert), configurable: true, writable: true }) return must } exports.prototype.assert = function assert(orig, ok, msg, opts) { opts = opts ? Object.create(opts) : {} if ("stack" in this) opts.stack = this.stack orig.call(this, ok, msg, opts) } exports.prototype.then = function(fn, args, actual) { this.actual = actual fn.apply(this, args) } function hasFunction(obj, name) { return !lookupGetter(obj, name) && typeof obj[name] == "function" } js-must-0.13.4/must.d.ts000066400000000000000000000044341303625023100147630ustar00rootroot00000000000000interface Must { a: CallableMust; above(expected): Must; after(expected): Must; an: CallableMust; array(): Must; at: Must; be: CallableMust; before(expected): Must; below(expected): Must; between(begin, end): Must; boolean(): Must; contain(expected): Must; date(expected): Must; empty(): Must; endWith(expected: string): Must; enumerable(property: string): Must; enumerableProperty(property: string): Must; eql(expected): Must; equal(expected): Must; error(constructor?, expected?): Must; eventually: Must; exist(): Must; false(): Must; falsy(): Must; frozen(): Must; function(): Must; gt(expected: number): Must; gte(expected: number): Must; have: Must; include(expected): Must; instanceOf(expected): Must; instanceof(expected): Must; is(expected): Must; keys(expected: Array): Must; least(expected): Must; length(expected: number): Must; lt(expected: number): Must; lte(expected: number): Must; match(expected): Must; most(expected: number): Must; must: Must; nan(): Must; nonenumerable(property: string): Must; nonenumerableProperty(property: string): Must; not: Must; null(): Must; number(): Must; object(): Must; own(property: string, value?): Must; ownKeys(keys: Array): Must; ownProperties(properties: any): Must; ownProperty(property: string, value?): Must; permutationOf(expected: Array): Must; properties(properties: any): Must; property(property: string, value?): Must; regexp(): Must; reject: Must; resolve: Must; startWith(expected: string): Must; string(): Must; symbol(): Must; the: Must; then: Must; throw(constructor?, expected?): Must; to: Must; true(): Must; truthy(): Must; undefined(): Must; with: Must; } interface CallableMust extends Must { (): Must; } declare function must(expected: any): Must; declare namespace must {} export = must; declare global { interface String { must: Must; } interface Boolean { must: Must; } interface Number { must: Must; } interface Object { must: Must; } interface Array { must: Must; } } js-must-0.13.4/must.js000066400000000000000000001036401303625023100145260ustar00rootroot00000000000000var O = require("oolong") var AssertionError = require("./lib/assertion_error") var Resolvable = require("./lib/resolvable") var Rejectable = require("./lib/rejectable") var kindof = require("kindof") var egal = require("egal") var deepEgal = egal.deepEgal var stringify = require("./lib").stringify var chain = require("./lib").chain var defineGetter = O.defineGetter var lookupGetter = O.lookupGetter var startsWith = require("./lib/es6").startsWith var endsWith = require("./lib/es6").endsWith var hasOwn = Function.call.bind(Object.hasOwnProperty) var ANY = {} exports = module.exports = Must exports.AssertionError = AssertionError exports.stringify = stringify exports.chain = chain /** * The main class that wraps the asserted object and that you call matchers on. * * To include a custom error message for failure cases, pass a string as the * second argument. * * Most of the time you'll be using * [`Object.prototype.must`](#Object.prototype.must) to create this wrapper, but * occasionally you might want to assert `null`s or `undefined`s and in those * cases assigning `Must` to something like `expect` or `demand` works nicely. * * @example * true.must.be.true() * [].must.be.empty() * * var expect = require("must") * expect(null).to.be.null() * * var demand = require("must") * demand(undefined, "The undefined undefineds").be.undefined() * * @class Must * @constructor * @param actual * @param [message] */ function Must(actual, message) { if (!(this instanceof Must)) return new Must(actual, message) this.actual = actual if (message != null) this.message = message } /** * Can also be used a pass-through property for a fluent chain. * * @example * "Hello".must.be.a.string() * new Date().must.be.a(Date) * * @method a * @alias instanceof */ defineGetter(Must.prototype, "a", function() { return chain(this, this.instanceof) }) /** * Can also be used a pass-through property for a fluent chain. * * @example * [1, 2].must.be.an.array() * new AwesomeClass().must.be.an(AwesomeClass) * * @method an * @alias instanceof */ defineGetter(Must.prototype, "an", lookupGetter(Must.prototype, "a")) /** * Pass-through property for a fluent chain. * * @example * (42).must.be.at.most(69) * (1337).must.be.at.least(1337) * * @property at * @on prototype */ defineGetter(Must.prototype, "at", passthrough) /** * Can also be used as a pass-through property for a fluent chain. * * @example * true.must.be.true() * (42).must.be(42) * * @method be * @alias equal */ defineGetter(Must.prototype, "be", function() { return chain(this, this.equal) }) /** * Pass-through property for a fluent chain. * * @example * [1, 2].must.have.length(2) * * @property have * @on prototype */ defineGetter(Must.prototype, "have", passthrough) /** * Inverse the assertion. * Use it multiple times to create lots of fun! * `true.must.not.not.be.true()` :-) * * @example * true.must.not.be.true() * [].must.not.be.empty() * * @property not * @on prototype */ defineGetter(Must.prototype, "not", function() { // NOTE: Dear reader or plugin author, please don't depend on this property // name will remain as-is. If you really need to, let me know how you'd like // to use it. XO. var self = Object.create(this) self.negative = !self.negative return self }) /** * Pass-through property for a fluent chain. * * @example * var expect = require("must") * expect(true).to.be.true() * * var wish = require("must") * wish(life).to.be.truthy() * * @property to * @on prototype */ defineGetter(Must.prototype, "to", passthrough) /** * Assert object is `true`. * A boxed boolean object (`new Boolean(true`) is _not_ considered true. * * @example * true.must.be.true() * * @method true */ Must.prototype.true = function() { this.assert(this.actual === true, "be", {expected: true}) } /** * Assert object is `false`. * A boxed boolean object (`new Boolean(false`) is _not_ considered false. * * @example * false.must.be.false() * @method false * */ Must.prototype.false = function() { this.assert(this.actual === false, "be", {expected: false}) } /** * Assert object is `NaN`. * * @example * NaN.must.be.nan() * * @method nan */ Must.prototype.nan = function() { this.assert(this.actual !== this.actual, "be", {expected: NaN}) } /** * Assert object is `null`. * * Because JavaScript does not allow method calls on `null`, you'll have to * wrap an expected null with [`Must`](#Must). Assigning `require("must")` to * `expect` or `demand` works well. * * If you want to assert that an object's property is `null`, see * [`property`](#Must.prototype.property). * * @example * var demand = require("must") * demand(null).be.null() * * @method null */ Must.prototype.null = function() { this.assert(this.actual === null, "be", {expected: null}) } /** * Assert object is `undefined`. * * Because JavaScript does not allow method calls on `undefined`, you'll have to * wrap an expected undefined with [`Must`](#Must). Assigning `require("must")` * to `expect` or `demand` works well. * * If you want to assert that an object's property is `undefined`, see * [`property`](#Must.prototype.property). * * @example * var demand = require("must") * demand(undefined).be.undefined() * * @method undefined */ Must.prototype.undefined = function() { this.assert(this.actual === undefined, "be", {expected: undefined}) } /** * Assert object is a boolean (`true` or `false`). * Boxed boolean objects (`new Boolean`) are _not_ considered booleans. * * @example * true.must.be.a.boolean() * * @method boolean */ Must.prototype.boolean = function() { this.assert(typeof this.actual == "boolean", "be a boolean") } /** * Assert object is a number. * Boxed number objects (`new Number`) are _not_ considered numbers. * * @example * (42).must.be.a.number() * * @method number */ Must.prototype.number = function() { this.assert(typeof this.actual == "number", "be a number") } /** * Assert object is a string. * Boxed string objects (`new String`) are _not_ considered strings. * * @example * "Hello".must.be.a.string() * * @method string */ Must.prototype.string = function() { this.assert(typeof this.actual == "string", "be a string") } /** * Assert object is a symbol. * * @example * Symbol().must.be.a.symbol() * * @method symbol */ Must.prototype.symbol = function() { this.assert(typeof this.actual == "symbol", "be a symbol") } /** * Assert object is a date. * * @example * new Date().must.be.a.date() * * @method date */ Must.prototype.date = function() { this.assert(kindof(this.actual) == "date", "be a date") } /** * Assert object is a regular expression. * * @example * /[a-z]/.must.be.a.regexp() * * @method regexp */ Must.prototype.regexp = function() { this.assert(kindof(this.actual) == "regexp", "be a regular expression") } /** * Assert object is an array. * * @example * [42, 69].must.be.an.array() * * @method array */ Must.prototype.array = function() { this.assert(Array.isArray(this.actual), "be an array") } /** * Assert object is a function. * * @example * (function() {}).must.be.a.function() * * @method function */ Must.prototype.function = function() { this.assert(typeof this.actual == "function", "be a function") } /** * Assert object is an.. object. * * @example * ({}).must.be.an.object() * * @method object */ Must.prototype.object = function() { var ok = this.actual && typeof this.actual == "object" this.assert(ok, "be an object") } /** * Assert object is truthy (`!!obj`). * * Only `null`, `undefined`, `0`, `false` and `""` are falsy in JavaScript. * Everything else is truthy. * * @example * (42).must.be.truthy() * "Hello".must.be.truthy() * * @method truthy */ Must.prototype.truthy = function() { this.assert(this.actual, "be truthy") } /** * Assert object is falsy (`!obj`). * * Only `null`, `undefined`, `0`, `false` and `""` are falsy in JavaScript. * Everything else is truthy. * * @example * 0.must.be.falsy() * "".must.be.falsy() * * @method falsy */ Must.prototype.falsy = function() { this.assert(!this.actual, "be falsy") } /** * Assert object is exists and thereby is not null or undefined. * * @example * 0.must.exist() * "".must.exist() * ({}).must.exist() * * @method exist */ Must.prototype.exist = function() { this.assert(this.actual != null, "exist") } /** * Assert that an object is an instance of something. * Uses `obj instanceof expected`. * * @example * new Date().must.be.an.instanceof(Date) * * @method instanceof * @param class */ Must.prototype.instanceof = function(expected) { var ok = this.actual instanceof expected this.assert(ok, instanceofMessage.bind(this, expected), {expected: expected}) } function instanceofMessage(expected) { var type = expected.displayName || expected.name || stringify(expected) return "be an instance of " + type } /** * @method instanceOf * @alias instanceof */ Must.prototype.instanceOf = Must.prototype.instanceof /** * Assert that an object is empty. * Checks either the `length` for arrays and strings or the count of * enumerable keys. Inherited keys also counted. * * @example * "".must.be.empty() * [].must.be.empty() * ({}).must.be.empty() * * @method empty */ Must.prototype.empty = function() { var ok = false if (typeof this.actual === "string" || Array.isArray(this.actual)) ok = this.actual.length === 0 else if (typeof this.actual == "object" || typeof this.actual == "function") ok = O.isEmpty(this.actual) this.assert(ok, "be empty") } /** * Assert a string ends with the given string. * * @example * "Hello, John".must.endWith("John") * * @method endWith * @param expected */ Must.prototype.endWith = function(expected) { this.assert(endsWith(this.actual, expected), "end with", {expected: expected}) } /** * Assert object strict equality or identity (`===`). * * To compare value objects (like `Date` or `RegExp`) by their value rather * than identity, use [`eql`](#Must.prototype.eql). * To compare arrays and objects by content, also use * [`eql`](#Must.prototype.eql). * * @example * (42).must.equal(42) * * var date = new Date * date.must.equal(date) * * @method equal * @param expected */ Must.prototype.equal = function(expected) { this.assert(this.actual === expected, "equal", {expected: expected}) } /** * Assert that an object is an error (instance of `Error` by default). * Optionally assert it matches `expected` (and/or is of instance * `constructor`). * When you have a function that's supposed to throw, use * [`throw`](#Must.prototype.throw). * * Given `expected`, the error is asserted as follows: * - A **string** is compared with the exception's `message` property. * - A **regular expression** is matched against the exception's `message` * property. * - A **function** (a.k.a. constructor) is used to check if the error * is an `instanceof` that constructor. * - All other cases of `expected` are left unspecified for now. * * @example * var err = throw new RangeError("Everything's amazing and nobody's happy") } * err.must.be.an.error() * err.must.be.an.error("Everything's amazing and nobody's happy") * err.must.be.an.error(/amazing/) * err.must.be.an.error(Error) * err.must.be.an.error(RangeError) * err.must.be.an.error(RangeError, "Everything's amazing and nobody's happy") * err.must.be.an.error(RangeError, /amazing/) * * @method error * @param [constructor] * @param [expected] */ Must.prototype.error = function(type, expected) { if (arguments.length <= 1) expected = ANY if (arguments.length == 1 && !isFn(type)) { expected = type; type = null } var ok = isError(this.actual, type || Error, expected) var msg = expected !== ANY ? "be an error matching" : "be an error" var opts = expected !== ANY ? {expected: expected} : null this.assert(ok, msg, opts) } /** * Can also be used as a pass-through property for a fluent chain. * * @example * var claim = require("must") * claim(true).is.true() * claim(42).is(42) * * @method is * @alias equal */ defineGetter(Must.prototype, "is", lookupGetter(Must.prototype, "be")) /** * Assert object equality by content and if possible, recursively. * Also handles circular and self-referential objects. * * For most parts it asserts strict equality (`===`), but: * - `RegExp` objects are compared by their pattern and flags. * - `Date` objects are compared by their value. * - `Array` objects are compared recursively. * - `NaN`s are considered equivalent. * - Instances of the same class with a `valueOf` function are compared by its * output. * - Plain objects and instances of the same class are compared recursively. * * **Does not coerce types** so **mismatching types fail**. * Inherited enumerable properties are also taken into account. * * **Instances** are objects whose prototype's `constructor` property is set. * E.g. `new MyClass`. * Others, like `{}` or `Object.create({})`, are **plain objects**. * * @example * /[a-z]/.must.eql(/[a-z]/) * new Date(1987, 5, 18).must.eql(new Date(1987, 5, 18)) * ["Lisp", 42].must.eql(["Lisp", 42]) * ({life: 42, love: 69}).must.eql({life: 42, love: 69}) * NaN.must.eql(NaN) * * function Answer(answer) { this.answer = answer } * new Answer(42).must.eql(new Answer(42)) * * @method eql * @param expected */ Must.prototype.eql = function(expected) { var ok = deepEgal(this.actual, expected, eql) this.assert(ok, "be equivalent to", {expected: expected, diffable: true}) } /** * Assert object includes `expected`. * * For strings it checks the text, for arrays it checks elements and for * objects the property values. Everything is checked with strict equals * (`===`). * * @example * "Hello, John!".must.include("John") * [1, 42, 3].must.include(42) * ({life: 42, love: 69}).must.include(42) * * @method include * @param expected */ Must.prototype.include = function(expected) { var found if (typeof this.actual === "string" || Array.isArray(this.actual)) found = this.actual.indexOf(expected) >= 0 else for (var key in this.actual) if (this.actual[key] === expected) { found = true; break } this.assert(found, "include", {expected: expected}) } /** * @method contain * @alias include */ Must.prototype.contain = Must.prototype.include /** * Assert that an array is a permutation of the given array. * * An array is a permutation of another if they both have the same elements * (including the same number of duplicates) regardless of their order. * Elements are checked with strict equals (`===`). * * @example * [1, 1, 2, 3].must.be.a.permutationOf([3, 2, 1, 1]) * [7, 8, 8, 9].must.not.be.a.permutationOf([9, 8, 7]) * * @method permutationOf * @param expected */ Must.prototype.permutationOf = function(expected) { var ok = isPermutationOf(this.actual, expected) this.assert(ok, "be a permutation of", {expected: expected, diffable: true}) } function isPermutationOf(actual, expected) { if (!Array.isArray(actual) || !Array.isArray(expected)) return false if (actual.length !== expected.length) return false actual = actual.slice().sort() expected = expected.slice().sort() for (var i = 0; i < actual.length; i++) { if (actual[i] !== expected[i]) return false } return true } /** * Assert object matches the given regular expression. * * If you pass in a non regular expression object, it'll be converted to one * via `new RegExp(regexp)`. * * @example * "Hello, John!".must.match(/john/i) * "Wei wu wei".must.match("wu") * * @method match * @param regexp */ Must.prototype.match = function(expected) { var regexp = expected instanceof RegExp ? expected : new RegExp(expected) this.assert(regexp.exec(this.actual), "match", {expected: regexp}) } /** * Pass-through property for a fluent chain. * * @example * (42).must.must.must.must.equal(42) * * @property must * @on prototype */ defineGetter(Must.prototype, "must", passthrough) /** * Pass-through property for a fluent chain. * * @example * (42).must.be.the.number() * * @property the * @on prototype */ defineGetter(Must.prototype, "the", passthrough) /** * Assert that a function throws. * Optionally assert it throws `expected` (and/or is of instance * `constructor`). * When you already have an error reference, use * [`error`](#Must.prototype.error). * * Given `expected`, the error is asserted as follows: * - A **string** is compared with the exception's `message` property. * - A **regular expression** is matched against the exception's `message` * property. * - A **function** (a.k.a. constructor) is used to check if the error * is an `instanceof` that constructor. * - All other cases of `expected` are left unspecified for now. * * Because of how JavaScript works, the function will be called in `null` * context (`this`). If you want to test an instance method, bind it: * `obj.method.bind(obj).must.throw()`. * * @example * function omg() { * throw new RangeError("Everything's amazing and nobody's happy") * } * * omg.must.throw() * omg.must.throw("Everything's amazing and nobody's happy") * omg.must.throw(/amazing/) * omg.must.throw(Error) * omg.must.throw(RangeError) * omg.must.throw(RangeError, "Everything's amazing and nobody's happy") * omg.must.throw(RangeError, /amazing/) * * @method throw * @param [constructor] * @param [expected] */ Must.prototype.throw = function(type, expected) { if (arguments.length <= 1) expected = ANY if (arguments.length == 1 && !isFn(type)) { expected = type; type = null } var ok = false, exception try { this.actual.call(null) } catch (ex) { ok = true; exception = ex } ok = ok && isError(exception, type, expected) var opts = {actual: exception} if (expected !== ANY) opts.expected = expected this.assert(ok, "throw", opts) } /** * Assert that an object has a length property equal to `expected`. * * @example * "Something or other".must.have.length(18) * [1, 2, 3, "Four o'clock rock"].must.have.length(4) * * @method length * @param expected */ Must.prototype.length = function(expected) { var ok = this.actual.length == expected this.assert(ok, "have length of", {expected: expected}) } /** * Assert that an object is frozen with `Object.isFrozen`. * * @example * Object.freeze({}).must.be.frozen() * * @method frozen */ Must.prototype.frozen = function() { this.assert(Object.isFrozen(this.actual), "be frozen") } /** * Assert that an object has all of the properties given in `properties` with * equal (`===`) values. In other words, asserts that the given object is * a subset of the one asserted against. * * Takes **inherited properties** into account. To not do so, see * [`ownProperties`](#Must.prototype.ownProperties). * * @example * var john = {name: "John", age: 42, sex: "male"} * john.must.have.properties({name: "John", sex: "male"}) * * @method properties * @param properties */ Must.prototype.properties = function(props) { var obj = this.actual var ok = this.actual != null if (ok) for (var key in props) { ok = key in obj && obj[key] === props[key] if (!ok) break } this.assert(ok, "have properties", {expected: props, diffable: true}) } /** * Assert that an object has all of the properties given in `properties` with * equal (`===`) values and that they're own properties. In other words, * asserts that the given object is a subset of the one asserted against. * * **Does not** take **inherited properties** into account. To do so, see * [`properties`](#Must.prototype.properties). * * @example * var john = {name: "John", age: 42, sex: "male"} * john.must.have.ownProperties({name: "John", sex: "male"}) * * @method ownProperties * @param properties */ Must.prototype.ownProperties = function(props) { var obj = this.actual var ok = this.actual != null if (ok) for (var key in props) { ok = key in obj && hasOwn(obj, key) && obj[key] === props[key] if (!ok) break } this.assert(ok, "have own properties", {expected: props, diffable: true}) } /** * Assert that an object has property `property`. * Optionally assert it *equals* (`===`) to `value`. * * Takes **inherited properties** into account. To not do so, see * [`ownProperty`](#Must.prototype.ownProperty). * * @example * (function() {}).must.have.property("call") * ({life: 42, love: 69}).must.have.property("love", 69) * * @method property * @param property * @param [value] */ Must.prototype.property = function(property, expected) { var ok = this.actual != null && property in Object(this.actual) if (ok && arguments.length > 1) ok = this.actual[property] === expected var msg = "have property \"" + property + "\"", opts if (arguments.length > 1) { msg += " equal to"; opts = {expected: expected} } this.assert(ok, msg, opts) } /** * Assert that an object has own property `property`. * Optionally assert it *equals* (`===`) to `value`. * * **Does not** take **inherited properties** into account. To do so, see * [`property`](#Must.prototype.property). * * @example * ({life: 42, love: 69}).must.have.ownProperty("love", 69) * * @method ownProperty * @param property * @param [value] */ Must.prototype.ownProperty = function(property, expected) { var ok = this.actual != null ok = ok && hasOwn(this.actual, property) if (ok && arguments.length > 1) ok = this.actual[property] === expected var msg = "have own property \"" + property + "\"", opts if (arguments.length > 1) { msg += " equal to"; opts = {expected: expected} } this.assert(ok, msg, opts) } /** * @method own * @alias ownProperty */ Must.prototype.own = Must.prototype.ownProperty /** * Assert that an object has only the expected enumerable `keys`. * Pass an array of strings as `keys`. * * Takes **inherited properties** into account. To not do so, see * [`ownKeys`](#Must.prototype.ownKeys). * * @example * ({life: 42, love: 69}).must.have.keys(["life", "love"]) * Object.create({life: 42}).must.have.keys(["life"]) * * @method keys * @param keys */ Must.prototype.keys = function(expected) { var ok = this.actual != null ok = ok && isPermutationOf(O.keys(Object(this.actual)), expected) this.assert(ok, "have keys", {expected: expected}) } /** * Assert that an object has only the expected enumerable `keys` of its own. * Pass an array of strings as `keys`. * * **Does not** take **inherited properties** into account. To do so, see * [`keys`](#Must.prototype.keys). * * @example * ({life: 42, love: 69}).must.have.ownKeys(["life", "love"]) * * @method ownKeys * @param keys */ Must.prototype.ownKeys = function(expected) { var ok = this.actual != null ok = ok && isPermutationOf(Object.keys(Object(this.actual)), expected) this.assert(ok, "have own keys", {expected: expected}) } /** * Assert that an object has an enumerable property `property`. * It will fail if the object lacks the property entirely. * * This also checks inherited properties in the prototype chain, something which * `Object.prototype.propertyIsEnumerable` itself does not do. * * For checking if a property exists *and* is non-enumerable, see * [`nonenumerable`](#Must.prototype.nonenumerable). * * @example * ({life: 42, love: 69}).must.have.enumerable("love") * * @method enumerable * @param property */ Must.prototype.enumerable = function(property) { var ok = this.actual != null ok = ok && isEnumerable(Object(this.actual), property) this.assert(ok, "have enumerable property \"" + property + "\"") } /** * @method enumerableProperty * @alias enumerable */ Must.prototype.enumerableProperty = Must.prototype.enumerable /** * Assert that an object has a non-enumerable property `property`. * It will fail if the object lacks the property entirely. * * This also checks inherited properties in the prototype chain, something which * `Object.prototype.propertyIsEnumerable` itself does not do. * * It's the inverse of [`enumerable`](#Must.prototype.enumerable). * * @example * (function() {}).must.have.nonenumerable("call") * Object.create({}, {love: {enumerable: 0}}).must.have.nonenumerable("love") * * @method nonenumerable * @param property */ Must.prototype.nonenumerable = function(property) { var ok = this.actual != null ok = ok && property in Object(this.actual) ok = ok && !isEnumerable(Object(this.actual), property) this.assert(ok, "have nonenumerable property \"" + property + "\"") } function isEnumerable(obj, name) { // Using propertyIsEnumerable saves a possible looping of all keys. if (Object.prototype.propertyIsEnumerable.call(obj, name)) return true for (var key in obj) if (key == name) return true return false } /** * @method nonenumerableProperty * @alias nonenumerable */ Must.prototype.nonenumerableProperty = Must.prototype.nonenumerable /** * Assert that an object is below and less than (`<`) `expected`. * Uses `<` for comparison, so it'll also work with value objects (those * implementing [`valueOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)) like `Date`. * * @example * (42).must.be.below(69) * * @method below * @param expected */ Must.prototype.below = function(expected) { this.assert(this.actual < expected, "be below", {expected: expected}) } /** * @method lt * @alias below */ Must.prototype.lt = Must.prototype.below /** * Works well with dates where saying *before* is more natural than *below* or * *less than*. * * To assert that a date is equivalent to another date, use * [`eql`](#Must.prototype.eql). For regular numbers, * [`equal`](#Must.prototype.equal) is fine. * * @example * (42).must.be.before(1337) * new Date(2000, 5, 18).must.be.before(new Date(2001, 0, 1)) * * @method before * @alias below */ Must.prototype.before = Must.prototype.below /** * Assert that an object is at most, less than or equal to (`<=`), `expected`. * Uses `<=` for comparison, so it'll also work with value objects (those * implementing [`valueOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)) like `Date`. * * @example * (42).must.be.at.most(69) * (42).must.be.at.most(42) * * @method most * @param expected */ Must.prototype.most = function(expected) { this.assert(this.actual <= expected, "be at most", {expected: expected}) } /** * @method lte * @alias most */ Must.prototype.lte = Must.prototype.most /** * Assert that an object is above and greater than (`>`) `expected`. * Uses `>` for comparison, so it'll also work with value objects (those * implementing [`valueOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)) like `Date`. * * @example * (69).must.be.above(42) * * @method above * @param expected */ Must.prototype.above = function(expected) { this.assert(this.actual > expected, "be above", {expected: expected}) } /** * @method gt * @alias above */ Must.prototype.gt = Must.prototype.above /** * Works well with dates where saying *after* is more natural than *above* or * *greater than*. * * To assert that a date is equivalent to another date, use * [`eql`](#Must.prototype.eql). For regular numbers, * [`equal`](#Must.prototype.equal) is fine. * * @example * (1337).must.be.after(42) * new Date(2030, 5, 18).must.be.after(new Date(2013, 9, 23)) * * @method after * @alias above */ Must.prototype.after = Must.prototype.above /** * Assert that an object is at least, greater than or equal to (`>=`), * `expected`. * Uses `>=` for comparison, so it'll also work with value objects (those * implementing [`valueOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)) like `Date`. * * @example * (69).must.be.at.least(42) * (42).must.be.at.least(42) * * @method least * @param expected */ Must.prototype.least = function(expected) { this.assert(this.actual >= expected, "be at least", {expected: expected}) } /** * @method gte * @alias least */ Must.prototype.gte = Must.prototype.least /** * Assert that an object is between `begin` and `end` (inclusive). * Uses `<` for comparison, so it'll also work with value objects (those * implementing [`valueOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)) like `Date`. * * @example * (13).must.be.between(13, 69) * (42).must.be.between(13, 69) * (69).must.be.between(13, 69) * * @method between * @param begin * @param end */ Must.prototype.between = function(begin, end) { this.assert(begin <= this.actual && this.actual <= end, function() { return "be between " + stringify(begin) + " and " + stringify(end) }) } /** * Makes any matcher following the use of `resolve` wait till a promise * resolves before asserting. * Returns a new promise that will either resolve if the assertion passed or * fail with `AssertionError`. * * Promises are transparent to matchers, so everything will also work with * customer matchers you've added to `Must.prototype`. Internally Must just * waits on the promise and calls the matcher function once it's resolved. * * With [Mocha](http://mochajs.org), using this will look something like: * * ```javascript * it("must pass", function() { * return Promise.resolve(42).must.resolve.to.equal(42) * }) * ``` * * Using [CoMocha](https://github.com/blakeembrey/co-mocha), it'll look like: * ```javascript * it("must pass", function*() { * yield Promise.resolve(42).must.resolve.to.equal(42) * yield Promise.resolve([1, 2, 3]).must.resolve.to.not.include(42) * }) * ``` * * @example * Promise.resolve(42).must.resolve.to.equal(42) * Promise.resolve([1, 2, 3]).must.resolve.to.not.include(42) * * @property resolve * @on prototype */ defineGetter(Must.prototype, "resolve", function() { return Resolvable(this) }) /** * @example * Promise.resolve(42).must.then.equal(42) * * @property then * @on prototype * @alias resolve */ defineGetter(Must.prototype, "then", lookupGetter(Must.prototype, "resolve")) /** * @example * Promise.resolve(42).must.eventually.equal(42) * * @property eventually * @on prototype * @alias resolve */ defineGetter(Must.prototype, "eventually", lookupGetter(Must.prototype, "resolve")) /** * Makes any matcher following the use of `reject` wait till a promise * is rejected before asserting. * Returns a new promise that will either resolve if the assertion passed or * fail with `AssertionError`. * * Promises are transparent to matchers, so everything will also work with * customer matchers you've added to `Must.prototype`. Internally Must just * waits on the promise and calls the matcher function once it's rejected. * * With [Mocha](http://mochajs.org), using this will look something like: * * ```javascript * it("must pass", function() { * return Promise.reject(42).must.reject.to.equal(42) * }) * ``` * * Using [CoMocha](https://github.com/blakeembrey/co-mocha), it'll look like: * ```javascript * it("must pass", function*() { * yield Promise.reject(42).must.reject.to.equal(42) * yield Promise.reject([1, 2, 3]).must.reject.to.not.include(42) * }) * ``` * * @example * Promise.reject(42).must.reject.to.equal(42) * Promise.reject([1, 2, 3]).must.reject.to.not.include(42) * * @property reject * @on prototype */ defineGetter(Must.prototype, "reject", function() { return Rejectable(this) }) /** * Assert a string starts with the given string. * * @example * "Hello, John".must.startWith("Hello") * * @method startWith * @param expected */ Must.prototype.startWith = function(expected) { var ok = startsWith(this.actual, expected) this.assert(ok, "start with", {expected: expected}) } /** * Pass-through property for a fluent chain. * * @example * Promise.resolve(42).must.resolve.with.number() * * @property with * @on prototype */ defineGetter(Must.prototype, "with", passthrough) Must.prototype.assert = function assert(ok, message, opts) { if (!this.negative ? ok : !ok) return opts = opts ? Object.create(opts) : {} if (!("actual" in opts)) opts.actual = this.actual if (!("caller" in opts)) { // Accessing caller in strict mode throws TypeError. try { opts.caller = assert.caller } catch (ex) { opts.caller = assert } } var msg = stringify(this.actual) + " must " + (this.negative ? "not " : "") if (typeof message == "function") msg += message.call(this) else msg += message + ("expected" in opts ? " "+stringify(opts.expected) : "") if (this.message != null) msg = this.message + ": " + msg throw new AssertionError(msg, opts) } Object.defineProperty(Must.prototype, "assert", {enumerable: false}) function eql(a, b) { if (egal(a, b)) return true var type = kindofPlain(a) if (type !== kindofPlain(b)) return false if (isNumber(a) && isNumber(b) && isNaN(+a) && isNaN(+b)) return true switch (type) { case "array": case "plain": return null case "object": if (getConstructorOf(a) !== getConstructorOf(b)) return false if (hasValueOf(a) && hasValueOf(b)) return false return null default: return false } } function getConstructorOf(obj) { var prototype = Object.getPrototypeOf(obj) return prototype === null ? undefined : prototype.constructor } function hasValueOf(obj) { var valueOf = obj.valueOf return typeof valueOf === "function" && valueOf !== Object.prototype.valueOf } function kindofPlain(obj) { var type = kindof(obj) if (type === "object" && O.isPlainObject(obj)) return "plain" return type } function isError(err, constructor, expected) { if (constructor != null && !(err instanceof constructor)) return false if (expected === ANY) return true switch (kindof(expected)) { case "string": return messageFromError(err) === expected case "regexp": return expected.exec(messageFromError(err)) default: return err === expected } } function messageFromError(err) { // The message in new Error(message) gets converted to a string. return err == null || typeof err == "string" ? err : err.message } function isFn(fn) { return typeof fn === "function" } function isNumber(n) { return typeof n === "number" || n instanceof Number } function passthrough() { return this } js-must-0.13.4/package.json000066400000000000000000000021151303625023100154610ustar00rootroot00000000000000{ "name": "must", "version": "0.13.4", "description": "Testing and assertion library with friendly BDD syntax — awesome.must.be.true(). Many expressive matchers and is test runner and framework agnostic. Follows RFC 2119 with its use of MUST. Good and well tested stuff.", "keywords": ["assert", "assertion", "bdd", "test", "testing", "rfc2119"], "homepage": "https://github.com/moll/js-must", "bugs": "https://github.com/moll/js-must/issues", "author": { "name": "Andri Möll", "email": "andri@dot.ee", "url": "http://themoll.com" }, "typings": "./must.d.ts", "repository": { "type": "git", "url": "git://github.com/moll/js-must.git" }, "licenses" : [{ "type" : "LAGPL", "url": "https://github.com/moll/js-must/blob/master/LICENSE" }], "main": "register.js", "scripts": {"test": "make test"}, "dependencies": { "kindof": ">= 2.0.0 < 3", "egal": ">= 1.3.0 < 2", "oolong": ">= 1.11.0 < 2", "lodash.wrap": ">= 3 < 4", "json-stringify-safe": ">= 5 < 6" }, "devDependencies": { "mocha": ">= 2 < 3", "promise": ">= 7 < 8", "lodash": ">= 3 < 4" } } js-must-0.13.4/register.js000066400000000000000000000020521303625023100153550ustar00rootroot00000000000000var Must = module.exports = require("./must") /* eslint no-extend-native: 0 */ /** * Creates an instance of [`Must`](#Must) with the current object for asserting * and calling matchers on. * * This property is non-enumerable just like built-in properties, so * it'll never interfere with any regular usage of objects. * * Please note that JavaScript does not allow method calls on `null` or * `undefined`, so you'll sometimes have to call [`Must`](#Must) on them by * hand. Assigning `require("must")` to `expect` or `demand` works well with * those cases. * * @example * true.must.be.true() * [].must.be.empty() * * @property must * @for Object * @on prototype */ Object.defineProperty(Object.prototype, "must", { get: function() { "use strict"; return new Must(this) }, set: function(value) { Object.defineProperty(this, "must", { value: value, configurable: true, enumrable: true, writable: true }) }, // Without configurable, can't redefine it when reloading this file, e.g. configurable: true }) js-must-0.13.4/test/000077500000000000000000000000001303625023100141535ustar00rootroot00000000000000js-must-0.13.4/test/assertion_error_test.js000066400000000000000000000060751303625023100210000ustar00rootroot00000000000000var O = require("oolong") var assert = require("assert") var AssertionError = require("..").AssertionError describe("AssertionError", function() { it("must be named \"AssertionError\"", function() { var error = new AssertionError("foo") assert.strictEqual(error.name, "AssertionError") }) it("must have a constructor property", function() { assert.strictEqual(new AssertionError().constructor, AssertionError) }) it("must have constructor as a non-enumerable property", function() { var error = new AssertionError for (var key in error) assert.notEqual(key, "constructor") }) it("must have name", function() { assert.strictEqual(AssertionError.name, "AssertionError") }) describe("new", function() { it("must be an instance of AssertionError", function() { var error = new AssertionError("foo") assert(error instanceof AssertionError) }) it("must be an instance of Error", function() { var error = new AssertionError("foo") assert(error instanceof Error) }) it("must set actual if given", function() { var actual = {} var error = new AssertionError("", {actual: actual}) assert.strictEqual(error.actual, actual) }) it("must not set actual if not given", function() { var error = new AssertionError("") assert(!("actual" in error)) }) it("must set expected if given", function() { var expected = {} var error = new AssertionError("", {expected: expected}) assert.strictEqual(error.expected, expected) }) it("must not set expected if not given", function() { var error = new AssertionError("") assert(!("expected" in error)) }) it("must set diffable if given", function() { var error = new AssertionError("", {diffable: true}) assert.strictEqual(error.diffable, true) }) it("must not set diffable if not given", function() { var error = new AssertionError("") assert(!("diffable" in error)) }) }) describe(".prototype.showDiff", function() { it("must return the value of diffable", function() { var diffable = new AssertionError("", {diffable: true}) assert.strictEqual(diffable.showDiff, true) var undiffable = new AssertionError("", {diffable: false}) assert.strictEqual(undiffable.showDiff, false) }) }) describe(".prototype.stack", function() { it("must be unenumerable", function() { assert(O.keys(new AssertionError("Misery")).indexOf("assert") == -1) }) it("must be unenumerable if given", function() { var err = new AssertionError("Misery", {stack: "Problem at line 42"}) assert(O.keys(err).indexOf("assert") == -1) }) it("must use given stack and replace first line", function() { var a = new Error var b = new AssertionError("Misery", {stack: a.stack}) var aStackLines = a.stack.split(/\r?\n/) var bStackLines = b.stack.split(/\r?\n/) aStackLines.shift() bStackLines.shift().must.include("AssertionError: Misery") assert.deepEqual(aStackLines, bStackLines) }) }) }) js-must-0.13.4/test/lib/000077500000000000000000000000001303625023100147215ustar00rootroot00000000000000js-must-0.13.4/test/lib/index_test.js000066400000000000000000000133441303625023100174320ustar00rootroot00000000000000var assert = require("assert") var stringify = require("../..").stringify var describeSymbol = typeof Symbol != "undefined" ? describe : xdescribe var itSymbol = typeof Symbol != "undefined" ? it : xit var INDENT = null describe("Must.stringify", function() { it("must return undefined", function() { assert.strictEqual(stringify(undefined), "undefined") }) it("must return null", function() { assert.strictEqual(stringify(null), "null") }) describe("given Number", function() { it("must stringify 42 as 42", function() { assert.strictEqual(stringify(42), "42") }) it("must stringify Infinity as Infinity", function() { assert.strictEqual(stringify(Infinity), "Infinity") }) it("must stringify -Infinity as -Infinity", function() { assert.strictEqual(stringify(-Infinity), "-Infinity") }) it("must stringify NaN as NaN", function() { assert.strictEqual(stringify(NaN), "NaN") }) }) describe("given String", function() { it("must stringify quoted", function() { assert.strictEqual(stringify("Hello, world!"), "\"Hello, world!\"") }) }) describeSymbol("given Symbol", function() { it("must stringify a named symbol", function() { var symbol = Symbol("iterator") assert.strictEqual(stringify(symbol), "Symbol(iterator)") }) it("must stringify an unnamed symbol", function() { var symbol = Symbol() assert.strictEqual(stringify(symbol), "Symbol()") }) }) describe("given Date", function() { it("must stringify ISO string representation", function() { var date = new Date(Date.UTC(1987, 5, 18, 2)) assert.strictEqual(stringify(date), "1987-06-18T02:00:00.000Z") }) }) describe("given RegExp", function() { it("must stringify source with flags", function() { var regexp = /abc[de]./i assert.strictEqual(stringify(regexp), "/abc[de]./i") }) }) describe("given Function", function() { it("must stringify source", function() { function awesome() { return 42 } assert.strictEqual(stringify(awesome), "function awesome() { return 42 }") }) }) describe("given Array", function() { it("must stringify recursively", function() { var array = [{cool: 42}] assert.strictEqual(stringify(array), jsonify(array)) }) it("must stringify circular objects", function() { var array = [{name: "John"}, {name: "Mark"}] array[0].self = array[0] assert.strictEqual(stringify(array), jsonify([ {name: "John", self: "[Circular ~.0]"}, {name: "Mark"} ])) }) it("must stringify with toJSON", function() { var array = [{toJSON: function() { return 42 }}] assert.strictEqual(stringify(array), jsonify([42])) }) }) describe("given Object", function() { it("must stringify recursively", function() { var obj = {a: {cool: 42}} assert.strictEqual(stringify(obj), jsonify(obj)) }) it("must stringify inherited properties", function() { var obj = Object.create({a: 42}) assert.strictEqual(stringify(obj), jsonify({a: 42})) }) it("must stringify circular objects", function() { var obj = {name: "John", likes: {sex: true}} obj.self = obj assert.strictEqual(stringify(obj), jsonify({ name: "John", likes: {sex: true}, self: "[Circular ~]" })) }) it("must stringify nested circular objects", function() { var obj = {name: "John", likes: {}} obj.likes.likes = obj.likes var str = jsonify({name: "John", likes: {likes: "[Circular ~.likes]"}}) assert.strictEqual(stringify(obj), str) }) it("must stringify circular arrays", function() { var obj = [1, 2, 3] obj.push(obj) obj.push(5) assert.strictEqual(stringify(obj), jsonify([1, 2, 3, "[Circular ~]", 5])) }) it("must stringify circular inherited objects", function() { var obj = Object.create({name: "John"}) obj.self = obj var str = jsonify({self: "[Circular ~]", name: "John"}) assert.strictEqual(stringify(obj), str) }) it("must stringify undefined values", function() { var obj = {name: "John", age: undefined} var str = jsonify({name: "John", age: "[Undefined]"}) assert.strictEqual(stringify(obj), str) }) it("must stringify NaN", function() { var obj = {age: NaN} var str = jsonify({age: "[NaN]"}) assert.strictEqual(stringify(obj), str) }) it("must stringify with toJSON", function() { var obj = {age: {toJSON: function() { return 42 }}} assert.strictEqual(stringify(obj), jsonify({age: 42})) }) itSymbol("must stringify nested Symbol", function() { var obj = {name: "John", type: Symbol("person")} var str = jsonify({name: "John", type: "Symbol(person)"}) assert.strictEqual(stringify(obj), str) }) it("must stringify nested RegExp", function() { var obj = {name: "John", match: /tinder/i} var str = jsonify({name: "John", match: "/tinder/i"}) assert.strictEqual(stringify(obj), str) }) it("must not stringify nested Function", function() { var obj = {name: "John", greet: function() {}} assert.strictEqual(stringify(obj), jsonify({name: "John"})) }) }) describe("given Error", function() { it("must stringify the message", function() { var err = new Error("Problem") assert.strictEqual(stringify(err), jsonify({message: "Problem"})) }) it("must stringify other enumerable properties", function() { var err = new Error("Not Found") err.code = 404 var str = jsonify({code: 404, message: "Not Found"}) assert.strictEqual(stringify(err), str) }) }) }) function jsonify(obj) { return JSON.stringify(obj, null, INDENT) } js-must-0.13.4/test/mocha.opts000066400000000000000000000000321303625023100161440ustar00rootroot00000000000000--recursive --check-leaks js-must-0.13.4/test/must/000077500000000000000000000000001303625023100151435ustar00rootroot00000000000000js-must-0.13.4/test/must/_assertion_error_test.js000066400000000000000000000012371303625023100221220ustar00rootroot00000000000000var Must = require("../..") var assert = require("assert") module.exports = function(test, props) { describe("AssertionError", function() { it("must be thrown", function() { assert.throws(test, Must.AssertionError) }) it("must have all properties", function() { try { test() } catch (ex) { assert.deepEqual(ex, props) } }) it("must have correct stack trace", function() { try { test() } catch (ex) { var stack = ex.stack.split(/\r?\n/) assert(stack[0].match(/AssertionError/, "must include AssertionError")) assert(stack[1].match(/[\\\/]test[\\\/]/), "must have test at top") } }) }) } js-must-0.13.4/test/must/_boolean_test.js000066400000000000000000000031431303625023100203170ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") module.exports = function(name, truthy) { // Allow using new Boolean: /* jshint -W053 */ /* eslint no-new-wrappers: 0 */ var pass = truthy ? "pass" : "fail" var fail = truthy ? "fail" : "pass" var throws = truthy ? assert.fail : assert.pass var doesNotThrow = truthy ? assert.pass : assert.fail it("must "+pass+" given true primitive", function() { doesNotThrow(function() { Must(true).be[name]() }) }) it("must fail given true object", function() { assert.fail(function() { Must(new Boolean(true)).be[name]() }) }) it("must "+fail+" given false primitive", function() { throws(function() { Must(false).be[name]() }) }) it("must fail given false object", function() { assert.fail(function() { Must(new Boolean(false)).be[name]() }) }) it("must fail gracefully if null", function() { assert.fail(function() { Must(null).be[name]() }) }) it("must fail gracefully if undefined", function() { assert.fail(function() { Must(undefined).be[name]() }) }) it("must fail given zero number primitive", function() { assert.fail(function() { Must(0).be[name]() }) }) it("must fail given an empty string", function() { assert.fail(function() { Must("").be[name]() }) }) require("./_assertion_error_test")(function() { Must(!truthy).be[name]() }, { actual: !truthy, expected: truthy, message: !truthy + " must be " + truthy }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(truthy).not.be[name]() }) }) }) } js-must-0.13.4/test/must/_enumerable_test.js000066400000000000000000000074461303625023100210310ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") module.exports = function(name, truthy) { var pass = truthy ? "pass" : "fail" var fail = truthy ? "fail" : "pass" var throws = truthy ? assert.fail : assert.pass var doesNotThrow = truthy ? assert.pass : assert.fail it("must "+pass+" if property is enumerable", function() { var obj = {love: true} doesNotThrow(function() { Must(obj).have[name]("love") }) }) it("must "+pass+" if inherited property is enumerable", function() { function Fn() {} Fn.prototype.love = 69 doesNotThrow(function() { Must(new Fn()).have[name]("love") }) }) it("must "+fail+" if property is nonenumerable", function() { var obj = Object.create(Object.prototype, { love: {value: 69, enumerable: false}, }) throws(function() { Must(obj).have[name]("love") }) }) it("must "+fail+" if inherited property is nonenumerable", function() { function Fn() {} Fn.prototype = Object.create(Object.prototype, { love: {value: 69, enumerable: false}, }) throws(function() { Must(new Fn()).have[name]("love") }) }) it("must "+pass+" if function's property is enumerable", function() { function fn() {} fn.love = 69 doesNotThrow(function() { Must(fn).have[name]("love") }) }) it("must "+fail+" if function's property is nonenumerable", function() { function fn() {} Object.defineProperty(fn, "love", {value: 69, enumerable: false}) throws(function() { Must(fn).have[name]("love") }) }) afterEach(function() { delete String.prototype.life }) it("must "+pass+" if String.prototype's property is enumerable", function() { /* eslint no-extend-native: 0 */ String.prototype.life = 42 doesNotThrow(function() { Must("Hello").have[name]("life") }) }) it("must "+fail+" if String.prototype's property is nonenumerable", function() { Object.defineProperty(String.prototype, "life", { value: 42, enumerable: false, configurable: true }) throws(function() { Must("Hello").have[name]("life") }) }) afterEach(function() { delete Boolean.prototype.life }) it("must "+pass+" if false's Boolean.prototype's property is enumerable", function() { Boolean.prototype.life = 42 doesNotThrow(function() { Must(false).have[name]("life") }) }) it("must "+fail+" if false's Boolean.prototype's property is nonenumerable", function() { Object.defineProperty(Boolean.prototype, "life", { value: 42, enumerable: false, configurable: true }) throws(function() { Must(false).have[name]("life") }) }) it("must fail if property does not exist", function() { assert.fail(function() { Must({}).have[name]("love") }) }) it("must pass if object has "+name+" property named \"propertyIsEnumerable\"", function() { var obj = Object.create(Object.prototype, { propertyIsEnumerable: {value: false, enumerable: truthy} }) assert.pass(function() { Must(obj).have[name]("propertyIsEnumerable") }) }) it("must fail gracefully if null", function() { assert.fail(function() { Must(null).have[name]("love") }) }) it("must fail gracefully if undefined", function() { assert.fail(function() { Must(undefined).have[name]("love") }) }) var errObj = Object.create(Object.prototype, { life: {value: 42, enumerable: true}, love: {value: 69, enumerable: false}, }) var errProp = truthy ? "love" : "life" require("./_assertion_error_test")(function() { Must(errObj).have[name](errProp) }, { actual: {life: 42}, message: "{\"life\":42} must have "+name+" property \""+errProp+"\"" }) describe(".not", function() { var errProp = truthy ? "life" : "love" it("must invert the assertion", function() { assert.fail(function() { Must(errObj).not.have[name](errProp) }) }) }) } js-must-0.13.4/test/must/_error_test.js000066400000000000000000000063441303625023100200370ustar00rootroot00000000000000var _ = require("lodash") var Must = require("../..") var assert = require("./assert") module.exports = function(name, actualize) { var create = _.compose(Must, actualize) describe("as an error matcher", function() { describe("given String", function() { it("must pass given error with identical message", function() { assert.pass(function() { create(new Error("Oh no!"))[name]("Oh no!") }) }) it("must fail given error with part of identical message", function() { assert.fail(function() { create(new Error("Oh no!"))[name]("Oh no") }) }) it("must fail given error with unequivalent message", function() { assert.fail(function() { create(new Error("Oh no!"))[name]("Oh yes!") }) }) }) describe("given RegExp", function() { it("must pass given error with matching message", function() { assert.pass(function() { create(new Error("Oh no!"))[name](/no!/) }) }) it("must fail given error with unmatching message", function() { assert.fail(function() { create(new Error("Oh no!"))[name](/yes!/) }) }) }) describe("given Function", function() { // Intentionally do not subclass FakeError from Error. function FakeError(msg) { this.message = msg == null ? "" : msg } FakeError.prototype.message = "" it("must pass given error instance of function", function() { assert.pass(function() { create(new FakeError)[name](FakeError) }) }) it("must pass given error child instance of function", function() { assert.pass(function() { create(new TypeError)[name](Error) }) }) it("must fail given error instance of other function", function() { assert.fail(function() { create(new Error)[name](FakeError) }) }) it("must fail given error parent instance of function", function() { assert.fail(function() { create(new Error)[name](TypeError) }) }) describe("with String", function() { var err = new TypeError("Oh no!") it("must pass given error with identical message", function() { assert.pass(function() { create(err)[name](TypeError, "Oh no!") }) }) it("must fail given error other instance", function() { assert.fail(function() { create(err)[name](RangeError, "Oh no!") }) }) it("must fail given error with part of identical message", function() { assert.fail(function() { create(err)[name](TypeError, "Oh no") }) }) it("must fail given error with unequivalent message", function() { assert.fail(function() { create(err)[name](TypeError, "Oh yes!") }) }) }) describe("with RegExp", function() { var err = new TypeError("Oh no!") it("must pass given error with matching message", function() { assert.pass(function() { create(err)[name](TypeError, /no!/) }) }) it("must fail given error other instance", function() { assert.fail(function() { create(err)[name](RangeError, /no!/) }) }) it("must fail given error with unmatching message", function() { assert.fail(function() { create(err)[name](TypeError, /yes!/) }) }) }) }) }) } js-must-0.13.4/test/must/_keys_test.js000066400000000000000000000072261303625023100176610ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") module.exports = function(name, inheritable) { var pass = inheritable ? "pass" : "fail" var fail = inheritable ? "fail" : "pass" var throws = inheritable ? assert.fail : assert.pass var doesNotThrow = inheritable ? assert.pass : assert.fail it("must pass given an object with expected own keys", function() { assert.pass(function() { Must({a: 1, b: 2}).have[name](["a", "b"]) }) }) it("must pass given an object with zero keys", function() { assert.pass(function() { Must({}).have[name]([]) }) }) it("must fail given zero and non-zero number of keys", function() { assert.fail(function() { Must({}).have[name](["a"]) }) assert.fail(function() { Must({a: 1}).have[name]([]) }) }) it("must fail given a different amount of keys", function() { assert.fail(function() { Must({a: 1}).have[name](["a", "b"]) }) assert.fail(function() { Must({a: 1, b: 2}).have[name](["a"]) }) }) it("must not modify given array", function() { var keys = ["name", "age"] Must({name: "John", age: 13}).have[name](keys) assert.deepEqual(keys, ["name", "age"]) }) describe("given an inherited object", function() { it("must "+pass+" given an object with inherited expected keys", function() { var obj = Object.create({a: 1, b: 2}) doesNotThrow(function() { Must(obj).have[name](["a", "b"]) }) }) it("must "+pass+" given an object with some expected keys inherited", function() { var obj = Object.create({a: 1}, {b: {value: 2, enumerable: true}}) doesNotThrow(function() { Must(obj).have[name](["a", "b"]) }) }) it("must "+fail+" given an object with all expected keys as own", function() { var obj = Object.create({a: 1}, {b: {value: 2, enumerable: true}}) throws(function() { Must(obj).have[name](["b"]) }) }) it("must "+fail+" given an object with zero own keys", function() { throws(function() { Must(Object.create({a: 1})).have[name]([]) }) }) it("must fail given a different amount of keys", function() { assert.fail(function() { Must(Object.create({a: 1})).have[name](["a", "b"]) }) assert.fail(function() { Must(Object.create({a: 1, b: 2})).have[name](["a"]) }) }) }) it("must pass if function has key", function() { function fn() {} fn.love = 69 assert.pass(function() { Must(fn).have[name](["love"]) }) }) it("must "+pass+" if function has inherited key", function() { function fn() {} /* eslint no-proto: 0 */ var obj = {love: {value: 1, enumerable: 1}} fn.__proto__ = Object.create(fn.__proto__, obj) doesNotThrow(function() { Must(fn).have[name](["love"]) }) }) afterEach(function() { delete Number.prototype.life }) it("must "+pass+" if Number.prototype has inherited key", function() { /* eslint no-extend-native: 0 */ Object.defineProperty(Number.prototype, "life", { value: 42, enumerable: true, configurable: true }) doesNotThrow(function() { Must(42).have[name](["life"]) }) }) afterEach(function() { delete Boolean.prototype.life }) it("must "+pass+" if false's Boolean.prototype has property", function() { /* eslint no-extend-native: 0 */ Object.defineProperty(Boolean.prototype, "life", { value: 42, enumerable: true, configurable: true }) doesNotThrow(function() { Must(false).have[name](["life"]) }) }) it("must fail gracefully if null", function() { assert.fail(function() { Must(null).have[name](["love"]) }) }) it("must fail gracefully if undefined", function() { assert.fail(function() { Must(undefined).have[name](["love"]) }) }) } js-must-0.13.4/test/must/_properties_test.js000066400000000000000000000072151303625023100211000ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") module.exports = function(name, inheritable) { // Allow using new Number: /* jshint -W053 */ /* eslint no-new-wrappers: 0 */ var pass = inheritable ? "pass" : "fail" var doesNotThrow = inheritable ? assert.pass : assert.fail var errName = name.replace(/[A-Z]/, function(l) {return " "+l.toLowerCase()}) it("must pass if object is superset of given properties", function() { var obj = {name: "John", age: 42, sex: "male"} var props = {name: "John", age: 42} assert.pass(function() { Must(obj).have[name](props) }) }) it("must pass if object has all given properties", function() { var a = {name: "John", age: 42, sex: "male"} var b = {name: "John", age: 42, sex: "male"} assert.pass(function() { Must(a).have[name](b) }) }) it("must pass if given no properties", function() { assert.pass(function() { Must({name: "John"}).have[name]({}) }) }) it("must "+pass+" if object has inherited propertes", function() { var obj = Object.create({name: "John"}) obj.age = 42 obj.sex = "male" var props = {name: "John", age: 42} doesNotThrow(function() { Must(obj).have[name](props) }) }) it("must pass if given an object with an undefined property", function() { var obj = {name: "John", age: 42, sex: undefined} var props = {name: "John", sex: undefined} assert.pass(function() { Must(obj).have[name](props) }) }) it("must "+pass+" if object has inherited property as undefined", function() { var obj = Object.create({name: "John", age: undefined}) obj.sex = "male" var props = {age: undefined, sex: "male"} doesNotThrow(function() { Must(obj).have[name](props) }) }) it("must fail if one property missing", function() { var obj = {name: "John", sex: "male"} var props = {name: "John", age: 42} assert.fail(function() { Must(obj).have[name](props) }) }) // Catches whether the last property check overwrites all previous ones. it("must fail if only last given property set", function() { var obj = {name: "John", age: 42, sex: "male"} var props = {name: "Jake", sex: "male"} assert.fail(function() { Must(obj).have[name](props) }) }) it("must fail if object has one with an equivalent value", function() { var obj = {name: "John", age: 42, sex: "male"} var props = {name: "John", age: new Number(42)} assert.fail(function() { Must(obj).have[name](props) }) }) it("must fail if an undefined property missing", function() { var obj = {name: "John", age: 42} var props = {name: "John", sex: undefined} assert.fail(function() { Must(obj).have[name](props) }) }) it("must fail if object empty", function() { var props = {name: "John", age: 42} assert.fail(function() { Must({}).have[name](props) }) }) it("must fail gracefully if null", function() { assert.fail(function() { Must(null).have[name]({}) }) }) it("must fail gracefully if undefined", function() { assert.fail(function() { Must(undefined).have[name]({}) }) }) require("./_assertion_error_test")(function() { var obj = {name: "John", sex: "male"} var props = {name: "John", age: 42} Must(obj).have[name](props) }, { actual: {name: "John", sex: "male"}, expected: {name: "John", age: 42}, diffable: true, message: "{\"name\":\"John\",\"sex\":\"male\"} must have "+errName+" {\"name\":\"John\",\"age\":42}" }) describe(".not", function() { it("must invert the assertion", function() { var obj = {name: "John", age: 42, sex: "male"} var props = {name: "John", age: 42} assert.fail(function() { Must(obj).not.have[name](props) }) }) }) } js-must-0.13.4/test/must/_property_test.js000066400000000000000000000107761303625023100205760ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") module.exports = function(name, inheritable) { // Allow using new Number: /* jshint -W053 */ /* eslint no-new-wrappers: 0 */ var pass = inheritable ? "pass" : "fail" var doesNotThrow = inheritable ? assert.pass : assert.fail var errName = name.replace(/[A-Z]/, function(l) {return " "+l.toLowerCase()}) describe("given name", function() { it("must pass if object has property", function() { assert.pass(function() { Must({love: 69}).have[name]("love") }) }) it("must "+pass+" if object has inherited property", function() { var obj = Object.create({love: 69}) doesNotThrow(function() { Must(obj).have[name]("love") }) }) it("must fail if object doesn't have property", function() { assert.fail(function() { Must({}).have[name]("love") }) }) it("must pass if object has property as undefined", function() { assert.pass(function() { Must({love: undefined}).have[name]("love") }) }) it("must "+pass+" if object has inherited property as undefined", function() { var obj = Object.create({love: undefined}) doesNotThrow(function() { Must(obj).have[name]("love") }) }) require("./_assertion_error_test")(function() { Must({name: "John"}).have[name]("age") }, { actual: {name: "John"}, message: "{\"name\":\"John\"} must have "+errName+" \"age\"" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must({name: "John"}).not.have[name]("name") }) }) }) }) describe("given name and value", function() { it("must pass if object has property with identical value", function() { assert.pass(function() { Must({love: 69}).have[name]("love", 69) }) }) it("must "+pass+" if object has inherited property with identical value", function() { var obj = Object.create({love: 69}) doesNotThrow(function() { Must(obj).have[name]("love", 69) }) }) it("must fail if object doesn't have property", function() { assert.fail(function() { Must({}).have[name]("love", 69) }) }) it("must fail if object has property with equivalent value", function() { assert.fail(function() { Must({love: 69}).have[name]("love", new Number(69)) }) }) it("must pass if object has property asserted undefined", function() { assert.pass(function() { Must({love: undefined}).have[name]("love", undefined) }) }) it("must "+pass+" if object has inherited property asserted undefined", function() { var obj = Object.create({love: undefined}) doesNotThrow(function() { Must(obj).have[name]("love", undefined) }) }) require("./_assertion_error_test")(function() { Must({age: 13}).have[name]("age", 42) }, { actual: {age: 13}, expected: 42, message: "{\"age\":13} must have "+errName+" \"age\" equal to 42" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must({age: 42}).not.have[name]("age", 42) }) }) }) }) it("must pass if function has property", function() { function fn() {} fn.love = 69 assert.pass(function() { Must(fn).have[name]("love") }) }) it("must "+pass+" if function has inherited property", function() { function fn() {} /* eslint no-proto: 0 */ fn.__proto__ = Object.create(fn.__proto__, {love: {value: 69}}) doesNotThrow(function() { Must(fn).have[name]("love") }) }) afterEach(function() { delete String.prototype.life }) it("must "+pass+" if String.prototype has property", function() { /* eslint no-extend-native: 0 */ Object.defineProperty(String.prototype, "life", { value: 42, enumerable: false, configurable: true }) doesNotThrow(function() { Must("Hello").have[name]("life") }) }) afterEach(function() { delete Boolean.prototype.life }) it("must "+pass+" if false's Boolean.prototype has property", function() { /* eslint no-extend-native: 0 */ Object.defineProperty(Boolean.prototype, "life", { value: 42, enumerable: false, configurable: true }) doesNotThrow(function() { Must(false).have[name]("life") }) }) it("must fail gracefully if null", function() { assert.fail(function() { Must(null).have[name]("love") }) }) it("must fail gracefully if undefined", function() { assert.fail(function() { Must(undefined).have[name]("love") }) }) } js-must-0.13.4/test/must/_truthy_test.js000066400000000000000000000072311303625023100202410ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") module.exports = function(name, truthy) { // Allow using new Boolean: /* jshint -W053 */ /* eslint no-new-wrappers: 0 */ var pass = truthy ? "pass" : "fail" var fail = truthy ? "fail" : "pass" var throws = truthy ? assert.fail : assert.pass var doesNotThrow = truthy ? assert.pass : assert.fail it("must "+fail+" given null", function() { throws(function() { Must(null).be[name]() }) }) it("must "+fail+" given undefined", function() { throws(function() { Must(undefined).be[name]() }) }) describe("given Boolean", function() { it("must "+pass+" given true primitive", function() { doesNotThrow(function() { Must(true).be[name]() }) }) it("must "+pass+" given true object", function() { doesNotThrow(function() { Must(new Boolean(true)).be[name]() }) }) it("must "+fail+" given false primitive", function() { throws(function() { Must(false).be[name]() }) }) it("must "+pass+" given false object", function() { doesNotThrow(function() { Must(new Boolean(false)).be[name]() }) }) }) describe("given Number", function() { it("must "+pass+" given primitive", function() { doesNotThrow(function() { Must(1).be[name]() }) }) it("must "+pass+" given object", function() { doesNotThrow(function() { Must(new Number(1)).be[name]() }) }) it("must "+fail+" given zero primitive", function() { throws(function() { Must(0).be[name]() }) }) it("must "+pass+" given zero object", function() { doesNotThrow(function() { Must(new Number(0)).be[name]() }) }) }) describe("given String", function() { it("must "+pass+" given primitive", function() { doesNotThrow(function() { Must("truthy").be[name]() }) }) it("must "+pass+" given object", function() { doesNotThrow(function() { Must(new String("truthy")).be[name]() }) }) it("must "+pass+" given zero primitive", function() { doesNotThrow(function() { Must("0").be[name]() }) }) it("must "+pass+" given zero object", function() { doesNotThrow(function() { Must(new String("0")).be[name]() }) }) it("must "+fail+" given empty primitive", function() { throws(function() { Must("").be[name]() }) }) it("must "+pass+" given empty object", function() { doesNotThrow(function() { Must(new String("")).be[name]() }) }) }) describe("given RegExp", function() { it("must "+pass+" given regexp", function() { doesNotThrow(function() { Must(new RegExp).be[name]() }) }) }) describe("given Date", function() { it("must "+pass+" given date", function() { doesNotThrow(function() { Must(new Date(0)).be[name]() }) }) }) describe("given Array", function() { it("must "+pass+" given empty array", function() { doesNotThrow(function() { Must([]).be[name]() }) }) }) describe("given Function", function() { it("must "+pass+" given function", function() { doesNotThrow(function() { Must(function() {}).be[name]() }) }) }) describe("given Object", function() { it("must "+pass+" given empty object", function() { doesNotThrow(function() { Must({}).be[name]() }) }) }) it("must not do anything when not called as a function", function() { assert.pass(function() { void Must(!truthy).be[name] }) }) require("./_assertion_error_test")(function() { Must(!truthy).be[name]() }, { actual: !truthy, message: !truthy + " must be " + name }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(truthy).not.be[name]() }) }) }) } js-must-0.13.4/test/must/a_test.js000066400000000000000000000016701303625023100167640ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.a", function() { it("must return an instance of Must", function() { assert(Must(true).a instanceof Must) }) it("must carry over the current state", function() { assert.pass(function() { Must([]).be.a.instanceof(Array) }) }) it("must be like Must.prototype.instanceof", function() { assert.pass(function() { Must([]).be.a(Array) }) assert.fail(function() { Must({}).be.a(Array) }) }) require("./_assertion_error_test")(function() { Must("").be.a(Array) }, { actual: "", expected: Array, message: "\"\" must be an instance of Array" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must([]).not.be.a(Array) }) }) it("must carry over the current state", function() { assert.fail(function() { Must(true).not.be.a.truthy() }) }) }) }) js-must-0.13.4/test/must/above_test.js000066400000000000000000000013121303625023100176310ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe(".prototype.above", function() { it("must pass if above", function() { assert.pass(function() { Must(69).be.above(42) }) }) it("must fail if equal", function() { assert.fail(function() { Must(69).be.above(69) }) }) it("must fail if below", function() { assert.fail(function() { Must(69).be.above(1337) }) }) require("./_assertion_error_test")(function() { Must(42).be.above(69) }, { actual: 42, expected: 69, message: "42 must be above 69" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(69).not.be.above(42) }) }) }) }) js-must-0.13.4/test/must/after_test.js000066400000000000000000000003651303625023100176450ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.after", function() { it("must be an alias of Must.prototype.above", function() { assert.strictEqual(Must.prototype.after, Must.prototype.above) }) }) js-must-0.13.4/test/must/an_test.js000066400000000000000000000005051303625023100171360ustar00rootroot00000000000000var O = require("oolong") var Must = require("../..") var assert = require("./assert") describe("Must.prototype.an", function() { it("must be an alias of Must.prototype.a", function() { var a = O.lookupGetter(Must.prototype, "a") var an = O.lookupGetter(Must.prototype, "an") assert.strictEqual(an, a) }) }) js-must-0.13.4/test/must/array_test.js000066400000000000000000000022641303625023100176620ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.array", function() { it("must pass given array", function() { assert.pass(function() { Must([]).be.array() }) }) it("must fail given null", function() { assert.fail(function() { Must(null).be.array() }) }) it("must fail given undefined", function() { assert.fail(function() { Must(undefined).be.array() }) }) it("must fail given boolean primitive", function() { assert.fail(function() { Must(true).be.array() }) assert.fail(function() { Must(false).be.array() }) }) it("must fail given number primitive", function() { assert.fail(function() { Must(0).be.array() }) }) it("must fail given string primitive", function() { assert.fail(function() { Must("").be.array() }) }) it("must fail given object", function() { assert.fail(function() { Must({}).be.array() }) }) require("./_assertion_error_test")(function() { Must(42).be.array() }, { actual: 42, message: "42 must be an array" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must([]).not.be.array() }) }) }) }) js-must-0.13.4/test/must/assert.js000066400000000000000000000004411303625023100170010ustar00rootroot00000000000000var O = require("oolong") var assert = require("assert") var Must = require("../..") exports = module.exports = assert.bind(null) O.assign(exports, assert) exports.pass = function(fn) { exports.doesNotThrow(fn) } exports.fail = function(fn) { exports.throws(fn, Must.AssertionError) } js-must-0.13.4/test/must/assert_test.js000066400000000000000000000003671303625023100200470ustar00rootroot00000000000000var O = require("oolong") var Must = require("../..") var assert = require("./assert") describe("Must.prototype.assert", function() { it("must not be enumerable", function() { assert(O.keys(Must(undefined)).indexOf("assert") == -1) }) }) js-must-0.13.4/test/must/at_test.js000066400000000000000000000003271303625023100171460ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.at", function() { it("must return self", function() { var must = Must(true) assert.strictEqual(must.at, must) }) }) js-must-0.13.4/test/must/be_test.js000066400000000000000000000021471303625023100171320ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.be", function() { it("must return an instance of Must", function() { assert(Must(true).be instanceof Must) }) it("must carry over the current state", function() { assert.pass(function() { Must(true).be.true() }) }) it("must be like Must.prototype.equal", function() { assert.pass(function() { Must(false).be(false) }) assert.fail(function() { Must(true).be(false) }) assert.pass(function() { Must(42).be(42) }) assert.fail(function() { Must(42).be(1337) }) assert.pass(function() { var obj = {}; Must(obj).be(obj) }) assert.fail(function() { Must({}).be({}) }) }) require("./_assertion_error_test")(function() { Must(true).be(42) }, { actual: true, expected: 42, message: "true must equal 42" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(true).not.be(true) }) }) it("must carry over the current state", function() { assert.fail(function() { Must(true).not.be.true() }) }) }) }) js-must-0.13.4/test/must/before_test.js000066400000000000000000000003671303625023100200100ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.before", function() { it("must be an alias of Must.prototype.below", function() { assert.strictEqual(Must.prototype.before, Must.prototype.below) }) }) js-must-0.13.4/test/must/below_test.js000066400000000000000000000013121303625023100176450ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe(".prototype.below", function() { it("must pass if below", function() { assert.pass(function() { Must(42).be.below(69) }) }) it("must fail if equal", function() { assert.fail(function() { Must(69).be.below(69) }) }) it("must fail if above", function() { assert.fail(function() { Must(1337).be.below(69) }) }) require("./_assertion_error_test")(function() { Must(69).be.below(42) }, { actual: 69, expected: 42, message: "69 must be below 42" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(42).not.be.below(69) }) }) }) }) js-must-0.13.4/test/must/between_test.js000066400000000000000000000017221303625023100201730ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.between", function() { it("must fail if below", function() { assert.fail(function() { Must(41).be.between(42, 69) }) }) it("must pass if on lower bound", function() { assert.pass(function() { Must(42).be.between(42, 69) }) }) it("must pass if between", function() { assert.pass(function() { Must(50).be.between(42, 69) }) }) it("must pass if on higher bound", function() { assert.pass(function() { Must(69).be.between(42, 69) }) }) it("must fail if above", function() { assert.fail(function() { Must(70).be.between(42, 69) }) }) require("./_assertion_error_test")(function() { Must(13).be.between(42, 69) }, { actual: 13, message: "13 must be between 42 and 69" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(50).not.be.between(42, 69) }) }) }) }) js-must-0.13.4/test/must/boolean_test.js000066400000000000000000000027501303625023100201630ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.boolean", function() { // Allow using new Boolean: /* jshint -W053 */ /* eslint no-new-wrappers: 0 */ it("must fail given null", function() { assert.fail(function() { Must(null).be.boolean() }) }) it("must fail given undefined", function() { assert.fail(function() { Must(undefined).be.boolean() }) }) it("must pass given boolean primitive", function() { assert.pass(function() { Must(true).be.boolean() }) assert.pass(function() { Must(false).be.boolean() }) }) it("must fail given boolean object", function() { assert.fail(function() { Must(new Boolean(true)).be.boolean() }) assert.fail(function() { Must(new Boolean(false)).be.boolean() }) }) it("must fail given number primitive", function() { assert.fail(function() { Must(0).be.boolean() }) }) it("must fail given string primitive", function() { assert.fail(function() { Must("").be.boolean() }) }) it("must fail given array", function() { assert.fail(function() { Must([]).be.boolean() }) }) it("must fail given object", function() { assert.fail(function() { Must({}).be.boolean() }) }) require("./_assertion_error_test")(function() { Must(42).be.boolean() }, { actual: 42, message: "42 must be a boolean" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(true).not.be.boolean() }) }) }) }) js-must-0.13.4/test/must/contain_test.js000066400000000000000000000003751303625023100202000ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.contain", function() { it("must be an alias of Must.prototype.include", function() { assert.strictEqual(Must.prototype.contain, Must.prototype.include) }) }) js-must-0.13.4/test/must/date_test.js000066400000000000000000000024301303625023100174540ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.date", function() { it("must fail given null", function() { assert.fail(function() { Must(null).be.date() }) }) it("must fail given undefined", function() { assert.fail(function() { Must(undefined).be.date() }) }) it("must fail given boolean primitive", function() { assert.fail(function() { Must(true).be.date() }) assert.fail(function() { Must(false).be.date() }) }) it("must fail given number primitive", function() { assert.fail(function() { Must(0).be.date() }) }) it("must fail given string primitive", function() { assert.fail(function() { Must("").be.date() }) }) it("must fail given array", function() { assert.fail(function() { Must([]).be.date() }) }) it("must fail given object", function() { assert.fail(function() { Must({}).be.date() }) }) it("must pass given a date", function() { assert.pass(function() { Must(new Date).be.date() }) }) require("./_assertion_error_test")(function() { Must(42).be.date() }, { actual: 42, message: "42 must be a date" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(new Date).not.be.date() }) }) }) }) js-must-0.13.4/test/must/empty_test.js000066400000000000000000000105221303625023100176760ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.empty", function() { // Allow using new Boolean: /* jshint -W053 */ /* eslint no-new-wrappers: 0 */ describe("given Boolean", function() { it("must fail given a boolean primitive", function() { assert.fail(function() { Must(true).be.empty() }) assert.fail(function() { Must(false).be.empty() }) }) it("must pass given a boolean object", function() { assert.pass(function() { Must(new Boolean(true)).be.empty() }) assert.pass(function() { Must(new Boolean(false)).be.empty() }) }) it("must fail given a non-empty object with keys", function() { var obj = new Boolean(false) obj.life = 42 assert.fail(function() { Must(obj).be.empty() }) }) }) describe("given Number", function() { it("must fail given an zero primitive", function() { assert.fail(function() { Must(0).be.empty() }) }) it("must fail given a non-zero primitive", function() { assert.fail(function() { Must(1).be.empty() }) }) it("must pass given a zero object", function() { assert.pass(function() { Must(new Number).be.empty() }) }) it("must pass given a non-zero object", function() { assert.pass(function() { Must(new Number(1)).be.empty() }) }) it("must fail given a non-empty object with keys", function() { var obj = new Number(1) obj.life = 42 assert.fail(function() { Must(obj).be.empty() }) }) }) describe("given String", function() { it("must pass given an empty primitive", function() { assert.pass(function() { Must("").be.empty() }) }) it("must fail given a non-empty primitive", function() { assert.fail(function() { Must("a").be.empty() }) }) it("must pass given an empty object", function() { assert.pass(function() { Must(new String).be.empty() }) }) it("must fail given a non-empty object", function() { assert.fail(function() { Must(new String("a")).be.empty() }) }) }) describe("given RegExp", function() { it("must pass given an empty object", function() { assert.pass(function() { Must(new RegExp).be.empty() }) }) it("must pass given a non-empty object", function() { assert.pass(function() { Must(new RegExp("a")).be.empty() }) }) it("must fail given a non-empty object with keys", function() { var obj = new RegExp("a") obj.life = 42 assert.fail(function() { Must(obj).be.empty() }) }) }) describe("given Array", function() { it("must pass given an empty primitive", function() { assert.pass(function() { Must([]).be.empty() }) }) it("must fail given a non-empty primitive", function() { assert.fail(function() { Must([1]).be.empty() }) }) }) describe("given Function", function() { it("should pass given an empty object", function() { assert.pass(function() { Must(function() {}).be.empty() }) }) it("should pass given a non-empty object", function() { assert.pass(function() { Must(function() { assert() }).be.empty() }) }) it("should fail given a non-empty object with keys", function() { function fn() {} fn.life = 42 assert.fail(function() { Must(fn).be.empty() }) }) }) describe("given Object", function() { it("must pass given an empty object", function() { assert.pass(function() { Must({}).be.empty() }) }) it("must fail given a non-empty object", function() { assert.fail(function() { Must({life: 42}).be.empty() }) }) it("must fail given a non-empty inherited object", function() { assert.fail(function() { Must(Object.create({life: 42})).be.empty() }) }) }) describe("given instance", function() { function Foo() {} function Bar() { this.life = 42 } it("must pass given an empty instance", function() { assert.pass(function() { Must(new Foo()).be.empty() }) }) it("must fail given a non-empty instance", function() { assert.fail(function() { Must(new Bar()).be.empty() }) }) }) require("./_assertion_error_test")(function() { Must([1]).be.empty() }, { actual: [1], message: "[1] must be empty" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must([]).not.be.empty() }) }) }) }) js-must-0.13.4/test/must/end_with_test.js000066400000000000000000000024421303625023100203430ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.endWith", function() { describe("given string", function() { it("must pass if string ends with given shorter string", function() { assert.pass(function() { Must("Hello, John").endWith("John") }) }) it("must fail if string does not end with given shorter string", function() { assert.fail(function() { Must("Hello, John").endWith("Mike") }) }) it("must fail if string starts with given shorter string", function() { assert.fail(function() { Must("Hello, John").endWith("Hello") }) }) it("must fail if string contains given string", function() { assert.fail(function() { Must("Hello").endWith("l") }) }) it("must fail given a longer string", function() { assert.fail(function() { Must("Hello").endWith("John, Hello") }) assert.fail(function() { Must("Hello").endWith("Hello, John") }) }) }) require("./_assertion_error_test")(function() { Must("Hello").endWith("Bye") }, { actual: "Hello", expected: "Bye", message: "\"Hello\" must end with \"Bye\"" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must("Hello").not.endWith("lo") }) }) }) }) js-must-0.13.4/test/must/enumerable_property_test.js000066400000000000000000000004711303625023100226250ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.enumerableProperty", function() { it("must be an alias of Must.prototype.enumerable", function() { var enumerable = Must.prototype.enumerable assert.strictEqual(Must.prototype.enumerableProperty, enumerable) }) }) js-must-0.13.4/test/must/enumerable_test.js000066400000000000000000000001461303625023100206600ustar00rootroot00000000000000describe(".prototype.enumerable", function() { require("./_enumerable_test")("enumerable", true) }) js-must-0.13.4/test/must/eql_test.js000066400000000000000000000615501303625023100173300ustar00rootroot00000000000000var _ = require("lodash") var O = require("oolong") var Must = require("../..") var assert = require("./assert") describe("Must.prototype.eql", function() { // Allow using new Boolean, String, Number: /* jshint -W053 */ /* eslint no-new-wrappers: 0 */ function eql(a, b) { Must(a).be.eql(b) } testNull(eql) testBoolean(eql) testNumber(eql) testString(eql) testSymbol(eql) testRegExp(eql) testDate(eql) testFunction(eql) it("must fail given an empty array and empty object", function() { // Can't think of an assertion library that would be nuts enough to consider // {} equivalent to []. Oh yeah, I can! For fucks sake, this is reason #42 // why Must.js is better! assert.fail(function() { Must({}).be.eql([]) }) assert.fail(function() { Must([]).be.eql({}) }) }) describe("given Array", function() { it("must pass given equivalent empty arrays", function() { assert.pass(function() { Must([]).be.eql([]) }) }) it("must pass given empty array and Array.prototype", function() { assert.pass(function() { Must([]).be.eql(Array.prototype) }) }) it("must pass given equivalent arrays", function() { assert.pass(function() { Must([1]).be.eql([1]) }) }) it("must pass given identical arrays", function() { var array = [] assert.pass(function() { Must(array).be.eql(array) }) }) it("must fail given an empty and non-empty array", function() { assert.fail(function() { Must([]).be.eql([1]) }) assert.fail(function() { Must([1]).be.eql([]) }) }) it("must fail given a smaller and a larger array", function() { assert.fail(function() { Must([1]).be.eql([1, 2]) }) assert.fail(function() { Must([1, 2]).be.eql([1]) }) }) it("must pass given equivalent nested arrays", function() { assert.pass(function() { Must([1, [2], 3]).be.eql([1, [2], 3]) }) }) it("must fail given unequivalent nested arrays", function() { assert.fail(function() { Must([1, [2], 3]).be.eql([1, [42], 3]) }) }) describe("with circular references", function() { it("must pass if equivalent", function() { var a = [1, 2, 3] a.push(a) a.push(5) var b = [1, 2, 3] b.push(b) b.push(5) assert.pass(function() { Must(a).be.eql(b) }) }) it("must fail if only one circular", function() { var a = [1, 2, 3] a.push(a) a.push(5) var b = [1, 2, 3, [1, 2, 3, 5], 5] assert.fail(function() { Must(a).be.eql(b) }) assert.fail(function() { Must(b).be.eql(a) }) }) it("must fail if circular to different levels", function() { var a = [1, 2, 3] a.push(a) var b = [1, 2, 3] var bInside = [1, 2, 3] bInside.push(bInside) b.push(bInside) assert.fail(function() { Must(a).be.eql(b) }) assert.fail(function() { Must(b).be.eql(a) }) }) }) describe("with nested values", function() { function nestedEql(a, b) { Must([a]).be.eql([b]) } testNull(nestedEql) testBoolean(nestedEql) testNumber(nestedEql) testString(nestedEql) testSymbol(nestedEql) testRegExp(nestedEql) testDate(nestedEql) testFunction(nestedEql) }) }) describe("given Object", function() { testObjectProperties(eql, _.identity) it("must pass given empty inherited objects", function() { var a = Object.create({}) var b = Object.create({}) assert.pass(function() { Must(a).be.eql(b) }) }) it("must pass given empty ancestored objects", function() { var a = Object.create(Object.create({})) var b = Object.create(Object.create({})) assert.pass(function() { Must(a).be.eql(b) }) }) it("must pass given empty objects inherited from null", function() { var a = Object.create(null) var b = Object.create(null) assert.pass(function() { Must(a).be.eql(b) }) }) it("must pass given empty objects ancestored from null", function() { var a = Object.create(Object.create(null)) var b = Object.create(Object.create(null)) assert.pass(function() { Must(a).be.eql(b) }) }) it("must pass given equivalent inherited objects", function() { var a = Object.create({love: 42}) var b = Object.create({love: 42}) assert.pass(function() { Must(a).be.eql(b) }) }) it("must pass given equivalent ancestored objects", function() { var a = Object.create(Object.create({love: 42})) var b = Object.create(Object.create({love: 42})) assert.pass(function() { Must(a).be.eql(b) }) }) it("must pass given equivalent objects inherited from null", function() { var a = Object.create(null, {life: {value: 42, enumerable: true}}) var b = Object.create(null, {life: {value: 42, enumerable: true}}) assert.pass(function() { Must(a).be.eql(b) }) }) it("must pass given equivalent objects ancestored from null", function() { var a = Object.create(Object.create(null, { life: {value: 42, enumerable: true} })) var b = Object.create(Object.create(null, { life: {value: 42, enumerable: true} })) assert.pass(function() { Must(a).be.eql(b) }) }) it("must fail given unequivalent inherited objects", function() { var a = Object.create({love: 42}) var b = Object.create({love: 69}) assert.fail(function() { Must(a).be.eql(b) }) }) it("must fail given unequivalent ancestored objects", function() { var a = Object.create(Object.create({love: 42})) var b = Object.create(Object.create({love: 69})) assert.fail(function() { Must(a).be.eql(b) }) }) it("must fail given unequivalent objects inherited from null", function() { var a = Object.create(null, {life: {value: 42, enumerable: true}}) var b = Object.create(null, {life: {value: 69, enumerable: true}}) assert.fail(function() { Must(a).be.eql(b) }) }) it("must fail given unequivalent objects ancestored from null", function() { var a = Object.create(Object.create(null, { life: {value: 42, enumerable: true} })) var b = Object.create(Object.create(null, { life: {value: 69, enumerable: true} })) assert.fail(function() { Must(a).be.eql(b) }) }) }) describe("given Object with constructor", function() { function Attributes(attrs) { O.assign(this, attrs) } testObjectProperties(eql, function(attrs) { return new Attributes(attrs) }) it("must pass given equivalent objects", function() { function Value(value) { this.value = value } var a = new Value(42); a.name = "Something" var b = new Value(42); b.name = "Something" assert.pass(function() { Must(a).be.eql(b) }) }) it("must pass given non-function valueOfs", function() { function Value(value) { this.value = value } Value.prototype.valueOf = 42 var a = new Value(42) var b = new Value(42) assert.pass(function() { Must(a).be.eql(b) }) }) it("must pass given one with unenumerable valueOf", function() { function Value(value) { this.value = value } var a = new Value(42) var b = new Value(42) Object.defineProperty(b, "valueOf", { value: function() { return this.value }, configurable: 1, writable: 1 }) assert.pass(function() { Must(a).be.eql(b) }) }) it("must fail given unequivalent objects", function() { function Value(value) { this.value = value } var a = new Value(42); a.name = "Something" var b = new Value(42); b.name = "Other" assert.fail(function() { Must(a).be.eql(b) }) }) it("must fail given different constructors", function() { function A() {} function B() {} assert.fail(function() { Must(new A).eql(new B) }) }) it("must fail given instance and plain object", function() { function Model() {} var a = new Model, b = {} assert.fail(function() { Must(a).eql(b) }) assert.fail(function() { Must(b).eql(a) }) }) it("must fail given subclassed constructor", function() { function Value(value) { this.value = value } function MoreValue(value) { this.value = value } MoreValue.prototype = Object.create(Value.prototype, { constructor: {value: MoreValue, configurable: true, writable: true} }) var a = new Value(42) var b = new MoreValue(42) assert.fail(function() { Must(a).be.eql(b) }) }) }) describe("given Object with valueOf", function() { it("must pass given equal value", function() { function Valuable(value) { this.value = value } Valuable.prototype.valueOf = function() { return this.value } var a = new Valuable(42), b = new Valuable(42) assert.pass(function() { Must(a).eql(b) }) }) it("must pass given equal value with unequivalent properties", function() { function Valuable(value, other) { this.value = value this.other = other } Valuable.prototype.valueOf = function() { return this.value } var a = new Valuable(42, 1), b = new Valuable(42, 2) assert.pass(function() { Must(a).eql(b) }) }) it("must pass given equal value but different valueOfs", function() { function Valuable(value) { this.valueOf = function() { return value } } var a = new Valuable(42), b = new Valuable(42) assert.pass(function() { Must(a).eql(b) }) }) it("must fail given unequivalent values", function() { function Valuable(value) { this.value = value } Valuable.prototype.valueOf = function() { return this.value } var a = new Valuable(42), b = new Valuable(69) assert.fail(function() { Must(a).eql(b) }) }) it("must fail given differently typed values", function() { function Valuable(value) { this.value = value } Valuable.prototype.valueOf = function() { return this.value } var a = new Valuable(42), b = new Valuable("42") assert.fail(function() { Must(a).eql(b) }) }) it("must pass given equivalent array values", function() { function Value(value) { this.value = value } Value.prototype.valueOf = function() { return [42, this.value] } var a = new Value(42) var b = new Value(42) assert.pass(function() { Must(a).eql(b) }) }) it("must fail given unequivalent array values", function() { function Value(value) { this.value = value } Value.prototype.valueOf = function() { return [42, this.value] } var a = new Value(42) var b = new Value(69) assert.fail(function() { Must(a).eql(b) }) }) it("must pass given null inherited value objects", function() { function Value(value) { this.value = value } Value.prototype = Object.create(null, { constructor: {value: Value, configurable: true, writeable: true} }) Value.prototype.valueOf = function() { return this.value } var a = new Value(42) var b = new Value(42) assert.pass(function() { Must(a).eql(b) }) }) it("must fail given instance and plain object", function() { function Value(value) { this.value = value } Value.prototype.valueOf = function() { return this.value } var a = new Value(42) var b = {valueOf: function() { return 42 }} assert.fail(function() { Must(a).eql(b) }) }) it("must fail given different construtors", function() { function A(value) { this.value = value } A.prototype.valueOf = function() { return this.value } function B(value) { this.value = value } B.prototype.valueOf = function() { return this.value } assert.fail(function() { Must(new A(42)).eql(new B(42)) }) }) it("must fail given subclassed constructor", function() { function Value(value) { this.value = value } Value.prototype.valueOf = function() { return this.value } function MoreValue(value) { this.value = value } MoreValue.prototype = Object.create(Value.prototype, { constructor: {value: MoreValue, configurable: true, writable: true} }) var a = new Value(42) var b = new MoreValue(42) assert.fail(function() { Must(a).eql(b) }) }) it("must fail given overwritten constructor properties", function() { function A(value) { this.value = value } A.prototype.valueOf = function() { return this.value } function B(value) { this.value = value } B.prototype.valueOf = function() { return this.value } var a = new A(42) var b = new B(42) a.constructor = b.constructor = function() {} assert.fail(function() { Must(a).eql(b) }) }) it("must return false given plain object", function() { var a = {valueOf: function() { return 1 }} var b = {valueOf: function() { return 1 }} assert.fail(function() { Must(a).eql(b) }) }) it("must return false given null inherited plain objects", function() { var a = Object.create(null); a.valueOf = function() { return 42 } var b = Object.create(null); b.valueOf = function() { return 42 } assert.fail(function() { Must(a).eql(b) }) }) }) require("./_assertion_error_test")(function() { Must("secret").eql(42) }, { actual: "secret", expected: 42, diffable: true, message: "\"secret\" must be equivalent to 42" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must("secret").not.eql("secret") }) }) }) }) function testNull(egal) { it("must pass given nulls", function() { assert.pass(function() { egal(null, null) }) }) it("must pass given undefineds", function() { assert.pass(function() { egal(undefined, undefined) }) }) it("must fail given null and undefined", function() { assert.fail(function() { egal(null, undefined) }) assert.fail(function() { egal(undefined, null) }) }) } function testBoolean(egal) { describe("given Boolean", function() { it("must pass given identical primitives", function() { assert.pass(function() { egal(true, true) }) assert.pass(function() { egal(false, false) }) }) it("must fail given unidentical primitives", function() { assert.fail(function() { egal(true, false) }) assert.fail(function() { egal(false, true) }) }) it("must pass given equivalent objects", function() { assert.pass(function() { egal(new Boolean(true), new Boolean(true)) }) assert.pass(function() { egal(new Boolean(false), new Boolean(false)) }) }) it("must fail given unequivalent objects", function() { assert.fail(function() { egal(new Boolean(true), new Boolean(false)) }) assert.fail(function() { egal(new Boolean(false), new Boolean(true)) }) }) it("must fail given equivalent primitive and object", function() { assert.fail(function() { egal(true, new Boolean(true)) }) assert.fail(function() { egal(new Boolean(true), true) }) assert.fail(function() { egal(false, new Boolean(false)) }) assert.fail(function() { egal(new Boolean(false), false) }) }) }) } function testNumber(egal) { describe("given Number", function() { it("must pass given identical primitives", function() { assert.pass(function() { egal(42, 42) }) }) it("must fail given unequivalent primitives", function() { assert.fail(function() { egal(42, 1337) }) }) it("must pass given equivalent objects", function() { assert.pass(function() { egal(new Number(42), new Number(42)) }) }) it("must fail given unequivalent objects", function() { assert.fail(function() { egal(new Number(42), new Number(69)) }) }) it("must fail given equivalent primitive and object", function() { assert.fail(function() { egal(42, new Number(42)) }) assert.fail(function() { egal(new Number(42), 42) }) }) it("must fail given string primitive", function() { assert.fail(function() { egal(42, "42") }) }) it("must fail given string object", function() { assert.fail(function() { egal(42, new String("42")) }) }) describe("given -0", function() { it("must pass given primitives", function() { assert.pass(function() { egal(-0, +0) }) assert.pass(function() { egal(+0, -0) }) }) it("must pass given objects", function() { assert.pass(function() { egal(new Number(-0), new Number(+0)) }) assert.pass(function() { egal(new Number(+0), new Number(-0)) }) }) it("must fail given primitive and object", function() { assert.fail(function() { egal(-0, new Number(+0)) }) assert.fail(function() { egal(new Number(-0), +0) }) }) }) describe("given NaN", function() { it("must pass given primitives", function() { assert.pass(function() { egal(NaN, NaN) }) }) it("must pass given objects", function() { assert.pass(function() { egal(new Number(NaN), new Number(NaN)) }) }) it("must fail given primitive and object", function() { assert.fail(function() { egal(NaN, new Number(NaN)) }) assert.fail(function() { egal(new Number(NaN), NaN) }) }) it("must fail given number and NaN", function() { assert.fail(function() { egal(42, NaN) }) assert.fail(function() { egal(NaN, 42) }) }) }) describe("given Infinity", function() { it("must pass given identical primitives", function() { assert.pass(function() { egal(Infinity, Infinity) }) assert.pass(function() { egal(-Infinity, -Infinity) }) }) it("must fail given unequivalent primitives", function() { assert.fail(function() { egal(Infinity, -Infinity) }) assert.fail(function() { egal(-Infinity, Infinity) }) }) it("must pass given equivalent objects", function() { assert.pass(function() { egal(new Number(Infinity), new Number(Infinity)) }) assert.pass(function() { egal(new Number(-Infinity), new Number(-Infinity)) }) }) it("must fail given unequivalent objects", function() { assert.fail(function() { egal(new Number(Infinity), new Number(-Infinity)) }) assert.fail(function() { egal(new Number(-Infinity), new Number(Infinity)) }) }) it("must fail given equivalent primitive and object", function() { assert.fail(function() { egal(Infinity, new Number(Infinity)) }) assert.fail(function() { egal(new Number(Infinity), Infinity) }) assert.fail(function() { egal(-Infinity, new Number(-Infinity)) }) assert.fail(function() { egal(new Number(-Infinity), -Infinity) }) }) it("must fail given number and infinity", function() { assert.fail(function() { egal(42, Infinity) }) assert.fail(function() { egal(42, -Infinity) }) }) }) }) } function testString(egal) { describe("given String", function() { it("must pass given identical primitives", function() { assert.pass(function() { egal("ok", "ok") }) }) it("must fail given unequivalent primitives", function() { assert.fail(function() { egal("ok", "nok") }) }) it("must pass given equivalent objects", function() { assert.pass(function() { egal(new String("a"), new String("a")) }) }) it("must fail given unequivalent objects", function() { assert.fail(function() { egal(new String("a"), new String("b")) }) }) it("must fail given equivalent primitive and object", function() { assert.fail(function() { egal("ok", new String("ok")) }) assert.fail(function() { egal(new String("ok"), "ok") }) }) it("must fail given equivalent number primitive", function() { assert.fail(function() { egal("1", 1) }) }) it("must fail given equivalent number object", function() { assert.fail(function() { egal("1", new Number(1)) }) }) }) } function testSymbol(egal) { var desc = typeof Symbol != "undefined" ? describe : xdescribe desc("given Symbol", function() { it("must pass given identical symbols", function() { var symbol = Symbol() assert.pass(function() { egal(symbol, symbol) }) }) it("must fail given two anonymous symbols", function() { assert.fail(function() { egal(Symbol(), Symbol()) }) }) it("must fail given two named symbols", function() { assert.fail(function() { egal(Symbol("iterator"), Symbol("iterator")) }) }) }) } function testRegExp(egal) { describe("given RegExp", function() { it("must pass given equivalent regexps", function() { assert.pass(function() { egal(/a/, /a/) }) }) it("must fail given unequivalent regexps", function() { assert.fail(function() { egal(/a/, /b/) }) }) it("must fail given unequivalent flags", function() { assert.fail(function() { egal(/a/ig, /a/g) }) }) it("must fail given RegExp and string primitive", function() { assert.fail(function() { egal(/a/, "/a/") }) }) }) } function testDate(egal) { describe("given Date", function() { it("must pass given identical dates", function() { var now = new Date assert.pass(function() { egal(now, now) }) }) it("must pass given equivalent dates", function() { assert.pass(function() { egal(new Date(7), new Date(7)) }) }) it("must fail given unequivalent dates", function() { assert.fail(function() { egal(new Date(69), new Date(42)) }) }) it("must fail given Date and number primitive", function() { assert.fail(function() { egal(new Date(69), 69) }) }) }) } function testFunction(egal) { describe("given Function", function() { it("must pass given identical functions", function() { function fn() {} assert.pass(function() { egal(fn, fn) }) }) it("must fail given equivalent functions", function() { assert.fail(function() { egal(function() {}, function() {}) }) }) }) } function testObjectProperties(egal, create) { describe("given Object with properties", function() { it("must pass given identical objects", function() { var obj = create({a: 42, b: 69}) assert.pass(function() { egal(obj, obj) }) }) it("must pass given empty objects", function() { assert.pass(function() { Must(create({})).be.eql(create({})) }) }) it("must fail given an empty and filled object", function() { assert.fail(function() { egal({}, create({a: 42})) }) assert.fail(function() { Must(create({a: 42})).be.eql(create({})) }) }) it("must fail given a smaller and larger object", function() { var a = create({a: 42, b: 69}) var b = create({a: 42}) assert.fail(function() { egal(a, b) }) assert.fail(function() { egal(b, a) }) }) // This was a bug I discovered on Jun 12, 2015 related to not comparing // keys equivalence before comparing their values. it("must fail given equal amount of keys undefined keys", function() { var obj = {name: undefined} assert.fail(function() { egal(obj, {age: undefined}) }) assert.fail(function() { egal(obj, {age: 13}) }) }) it("must pass given equivalent objects", function() { var a = create({a: 42, b: 69}) var b = create({a: 42, b: 69}) assert.pass(function() { egal(a, b) }) }) it("must fail given objects with differently typed properties", function() { var a = create({a: "42", b: 69}) var b = create({a: 42, b: 69}) assert.fail(function() { egal(a, b) }) }) it("must pass given an object with set constructor property", function() { var a = create({constructor: 1337}) var b = create({constructor: 1337}) assert.pass(function() { egal(a, b) }) }) it("must pass given a deep object", function() { var a = create({life: {love: 69}}) var b = create({life: {love: 69}}) assert.pass(function() { egal(a, b) }) }) it("must fail given an unequivalent deep object", function() { var a = create({life: {love: 69}}) var b = create({life: {love: 42}}) assert.fail(function() { egal(a, b) }) }) describe("with circular references", function() { it("must pass if equivalent", function() { var a = create({life: {love: 69}}) a.self = a var b = create({life: {love: 69}}) b.self = b assert.pass(function() { egal(a, b) }) }) it("must fail if only one circular", function() { var a = create({life: {love: 69}}) a.self = a var b = create({life: {love: 69}}) b.self = {life: {love: 69}, self: {}} assert.fail(function() { egal(a, b) }) assert.fail(function() { egal(b, a) }) }) it("must fail if circular to different levels", function() { var a = create({life: {love: 69}}) a.self = a var b = create({life: {love: 69}}) var bInside = create({life: {love: 69}}) bInside.self = bInside b.self = bInside assert.fail(function() { egal(a, b) }) assert.fail(function() { egal(b, a) }) }) }) }) } js-must-0.13.4/test/must/equal_test.js000066400000000000000000000110471303625023100176520ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.equal", function() { // Allow using new Boolean: /* jshint -W053 */ /* eslint no-new-wrappers: 0 */ it("must pass given nulls", function() { assert.pass(function() { Must(null).be.equal(null) }) }) it("must pass given undefineds", function() { assert.pass(function() { Must(undefined).be.equal(undefined) }) }) it("must fail given null and undefined", function() { assert.fail(function() { Must(null).be.equal(undefined) }) }) it("must fail given undefined and null", function() { assert.fail(function() { Must(undefined).be.equal(null) }) }) describe("given Boolean", function() { function mustPassTrueEqual(bool) { it("must pass given "+bool+" primitives", function() { assert.pass(function() { Must(bool).be.equal(bool) }) }) it("must fail given "+bool+" primitive and object", function() { assert.fail(function() { Must(bool).be.equal(new Boolean(bool)) }) assert.fail(function() { Must(new Boolean(bool)).be.equal(bool) }) }) it("must fail given "+bool+" primitive with "+!bool, function() { assert.fail(function() { Must(bool).be.equal(!bool) }) }) } mustPassTrueEqual(true) mustPassTrueEqual(false) }) describe("given Number", function() { it("must pass given equivalent primitives", function() { assert.pass(function() { Must(42).be.equal(42) }) }) it("must fail given unequivalent primitives", function() { assert.fail(function() { Must(42).be.equal(1337) }) }) it("must fail given equivalent primitive and object", function() { assert.fail(function() { Must(42).be.equal(new Number(42)) }) assert.fail(function() { Must(new Number(42)).be.equal(42) }) }) it("must fail given string", function() { assert.fail(function() { Must(42).be.equal("42") }) }) }) describe("given String", function() { it("must pass given equivalent primitives", function() { assert.pass(function() { Must("ok").be.equal("ok") }) }) it("must fail given unequivalent primitives", function() { assert.fail(function() { Must("ok").be.equal("nok") }) }) it("must fail given equivalent primitive and object", function() { assert.fail(function() { Must("ok").be.equal(new String("ok")) }) assert.fail(function() { Must(new String("ok")).be.equal("ok") }) }) it("must fail given number", function() { assert.fail(function() { Must("42").be.equal(42) }) }) }) describe("given RegExp", function() { it("must fail given equivalent regexps", function() { assert.fail(function() { Must(/a/).be.equal(/a/) }) }) it("must fail given unequivalent regexps", function() { assert.fail(function() { Must(/a/).be.equal(/b/) }) }) it("must pass given identical regexps", function() { var regexp = new RegExp assert.pass(function() { Must(regexp).be.equal(regexp) }) }) it("must fail given equivalent regexps", function() { assert.fail(function() { Must(new RegExp).be.equal(new RegExp) }) }) }) describe("given Date", function() { it("must pass given identical dates", function() { var now = new Date assert.pass(function() { Must(now).be.equal(now) }) }) it("must fail given equivalent dates", function() { assert.fail(function() { Must(new Date(42)).be.equal(new Date(42)) }) }) }) describe("given Array", function() { it("must fail given equivalent arrays", function() { assert.fail(function() { Must([1]).be.equal([1]) }) }) it("must pass given identical arrays", function() { var array = [] assert.pass(function() { Must(array).be.equal(array) }) }) it("must fail given unidentical arrays", function() { assert.fail(function() { Must([]).be.equal([]) }) }) }) describe("given Function", function() { it("must pass given identical functions", function() { function fn() {} assert.pass(function() { Must(fn).be.equal(fn) }) }) it("must fail given equivalent functions", function() { assert.fail(function() { Must(function foo() {}).be.equal(function foo() {}) }) }) }) require("./_assertion_error_test")(function() { Must("secret").equal(42) }, { actual: "secret", expected: 42, message: "\"secret\" must equal 42" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must("secret").not.equal("secret") }) }) }) }) js-must-0.13.4/test/must/error_test.js000066400000000000000000000027571303625023100177040ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.error", function() { require("./_error_test")("error", function(err) { return err }) describe("given nothing", function() { it("must pass given error with no message", function() { assert.pass(function() { Must(new Error).error() }) }) it("must pass given error with message", function() { assert.pass(function() { Must(new Error("Problem")).error() }) }) it("must fail given undefined", function() { assert.fail(function() { Must(undefined).error() }) }) it("must fail given null", function() { assert.fail(function() { Must(null).error() }) }) it("must fail given a string", function() { assert.fail(function() { Must("").error() }) }) it("must fail given an object", function() { assert.fail(function() { Must({}).error() }) }) require("./_assertion_error_test")(function() { Must(42).error() }, { actual: 42, message: "42 must be an error" }) }) describe("given String", function() { var err = new Error("Problem") require("./_assertion_error_test")(function() { Must(err).error("Oh no!") }, { actual: err, expected: "Oh no!", message: "{\"message\":\"Problem\"} must be an error matching \"Oh no!\"" }) }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(new Error).not.error() }) }) }) }) js-must-0.13.4/test/must/eventually_test.js000066400000000000000000000005751303625023100207370ustar00rootroot00000000000000var O = require("oolong") var Must = require("../..") var assert = require("./assert") describe("Must.prototype.eventually", function() { it("must be an alias of Must.prototype.resolve", function() { var eventually = O.lookupGetter(Must.prototype, "eventually") var resolve = O.lookupGetter(Must.prototype, "resolve") assert.strictEqual(eventually, resolve) }) }) js-must-0.13.4/test/must/exist_test.js000066400000000000000000000015651303625023100177030ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.exist", function() { it("must fail if null", function() { assert.fail(function() { Must(null).exist() }) }) it("must fail if undefined", function() { assert.fail(function() { Must(undefined).exist() }) }) it("must pass if true", function() { assert.pass(function() { Must(true).exist() }) }) it("must pass if false", function() { assert.pass(function() { Must(false).exist() }) }) it("must pass if an object", function() { assert.pass(function() { Must({}).exist() }) }) require("./_assertion_error_test")(function() { Must(null).exist() }, { actual: null, message: "null must exist" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(true).not.exist() }) }) }) }) js-must-0.13.4/test/must/false_test.js000066400000000000000000000001361303625023100176320ustar00rootroot00000000000000describe("Must.prototype.false", function() { require("./_boolean_test")("false", false) }) js-must-0.13.4/test/must/falsy_test.js000066400000000000000000000001351303625023100176550ustar00rootroot00000000000000describe("Must.prototype.falsy", function() { require("./_truthy_test")("falsy", false) }) js-must-0.13.4/test/must/frozen_test.js000066400000000000000000000012011303625023100200350ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe(".prototype.frozen", function() { it("must pass if object is frozen", function() { assert.pass(function() { Must(Object.freeze({})).be.frozen() }) }) it("must fail if object is thawed", function() { assert.fail(function() { Must({}).be.frozen() }) }) require("./_assertion_error_test")(function() { Must({}).be.frozen() }, { actual: {}, message: "{} must be frozen" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(Object.freeze({})).not.be.frozen() }) }) }) }) js-must-0.13.4/test/must/function_test.js000066400000000000000000000030441303625023100203660ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.function", function() { it("must fail given null", function() { assert.fail(function() { Must(null).be.function() }) }) it("must fail given undefined", function() { assert.fail(function() { Must(undefined).be.function() }) }) it("must fail given boolean primitive", function() { assert.fail(function() { Must(true).be.function() }) assert.fail(function() { Must(false).be.function() }) }) it("must fail given number primitive", function() { assert.fail(function() { Must(0).be.function() }) }) it("must fail given string primitive", function() { assert.fail(function() { Must("").be.function() }) }) it("must fail given array", function() { assert.fail(function() { Must([]).be.function() }) }) it("must fail given object", function() { assert.fail(function() { Must({}).be.function() }) }) it("must pass given function", function() { assert.pass(function() { Must(function() {}).be.function() }) }) it("must pass given a function with changed __proto__", function() { function fn() {} /* eslint no-proto: 0 */ fn.__proto__ = {} assert.pass(function() { Must(fn).be.function() }) }) require("./_assertion_error_test")(function() { Must(42).be.function() }, { actual: 42, message: "42 must be a function" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(function() {}).not.be.function() }) }) }) }) js-must-0.13.4/test/must/gt_test.js000066400000000000000000000003571303625023100171570ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.gt", function() { it("must be an alias of Must.prototype.above", function() { assert.strictEqual(Must.prototype.gt, Must.prototype.above) }) }) js-must-0.13.4/test/must/gte_test.js000066400000000000000000000003611303625023100173170ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.gte", function() { it("must be an alias of Must.prototype.least", function() { assert.strictEqual(Must.prototype.gte, Must.prototype.least) }) }) js-must-0.13.4/test/must/have_test.js000066400000000000000000000003331303625023100174620ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.have", function() { it("must return self", function() { var must = Must(true) assert.strictEqual(must.have, must) }) }) js-must-0.13.4/test/must/include_test.js000066400000000000000000000042301303625023100201620ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.include", function() { // Allow using new String: /* jshint -W053 */ /* eslint no-new-wrappers: 0 */ describe("given String", function() { var primitive = "Hello! How are you?" var object = new String(primitive) it("must pass if given string primitive includes string primitive", function() { assert.pass(function() { Must(primitive).include("How") }) }) it("must fail if given string primitive does not include string primitive", function() { assert.fail(function() { Must(primitive).include("good") }) }) it("must fail if given string object includes string primitive", function() { assert.fail(function() { Must(object).include("How") }) }) }) describe("given Array", function() { it("must pass if given array includes number primitive", function() { assert.pass(function() { Must([1, 2, 3]).include(2) }) }) it("must fail if given array does not include number primitive", function() { assert.fail(function() { Must([1, 2, 3]).include(42) }) }) it("must fail if given array includes number object", function() { assert.fail(function() { Must([1, 2, 3]).include(new Number(2)) }) }) }) describe("given Object", function() { it("must pass if given object includes number primitive", function() { assert.pass(function() { Must({a: 1, b: 2, c: 3}).include(2) }) }) it("must fail if given array does not include number primitive", function() { assert.fail(function() { Must({a: 1, b: 2, c: 3}).include(42) }) }) it("must fail if given array includes number object", function() { var obj = ({a: 1, b: 2, c: 3}) assert.fail(function() { Must(obj).include(new Number(2)) }) }) }) require("./_assertion_error_test")(function() { Must([1, 2, 3]).include(42) }, { actual: [1, 2, 3], expected: 42, message: "[1,2,3] must include 42" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must([1, 42, 3]).not.include(42) }) }) }) }) js-must-0.13.4/test/must/instance_of_test.js000066400000000000000000000004111303625023100210240ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.instanceOf", function() { it("must be an alias of Must.prototype.instanceof", function() { assert.strictEqual(Must.prototype.instanceOf, Must.prototype.instanceof) }) }) js-must-0.13.4/test/must/instanceof_test.js000066400000000000000000000061211303625023100206710ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.instanceof", function() { // Allow using new Boolean: /* jshint -W053 */ /* eslint no-new-wrappers: 0 */ describe("given Boolean", function() { it("must fail given boolean primitive", function() { assert.fail(function() { Must(true).be.instanceof(Boolean) }) assert.fail(function() { Must(false).be.instanceof(Boolean) }) }) it("must pass given boolean object", function() { assert.pass(function() { Must(new Boolean()).be.instanceof(Boolean) }) }) it("must fail given Boolean constructor", function() { assert.fail(function() { Must(Boolean).be.instanceof(Boolean) }) }) }) describe("given Number", function() { it("must fail given number primitive", function() { assert.fail(function() { Must(42).be.instanceof(Number) }) }) it("must pass given number object", function() { assert.pass(function() { Must(new Number()).be.instanceof(Number) }) }) it("must fail given Number constructor", function() { assert.fail(function() { Must(Number).be.instanceof(Number) }) }) }) describe("given String", function() { it("must fail given string primitive", function() { assert.fail(function() { Must("").be.instanceof(String) }) }) it("must pass given string object", function() { assert.pass(function() { Must(new String()).be.instanceof(String) }) }) it("must fail given String constructor", function() { assert.fail(function() { Must(String).be.instanceof(String) }) }) }) describe("given Array", function() { it("must pass given array", function() { assert.pass(function() { Must([]).be.instanceof(Array) }) }) it("must fail given Array constructor", function() { assert.fail(function() { Must(Array).be.instanceof(Array) }) }) }) describe("given Function", function() { it("must pass given function object", function() { assert.pass(function() { Must(function() {}).be.instanceof(Function) }) }) it("must pass given Function constructor", function() { assert.pass(function() { Must(Function).be.instanceof(Function) }) }) }) describe("given instance", function() { function Foo() {} function Bar() {} it("must pass given an instance of it", function() { assert.pass(function() { Must(new Foo()).be.instanceof(Foo) }) }) it("must pass given an instance of it and Object", function() { assert.pass(function() { Must(new Foo()).be.instanceof(Object) }) }) it("must fail given an instance of another", function() { assert.fail(function() { Must(new Bar()).be.instanceof(Foo) }) }) }) require("./_assertion_error_test")(function() { Must([]).be.instanceof(String) }, { actual: [], expected: String, message: "[] must be an instance of String" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must([]).not.be.instanceof(Array) }) }) }) }) js-must-0.13.4/test/must/is_test.js000066400000000000000000000005111303625023100171500ustar00rootroot00000000000000var O = require("oolong") var Must = require("../..") var assert = require("./assert") describe("Must.prototype.is", function() { it("must be an alias of Must.prototype.be", function() { var be = O.lookupGetter(Must.prototype, "be") var is = O.lookupGetter(Must.prototype, "is") assert.strictEqual(is, be) }) }) js-must-0.13.4/test/must/keys_test.js000066400000000000000000000010151303625023100175100ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.keys", function() { require("./_keys_test")("keys", true) require("./_assertion_error_test")(function() { Must({a: 1}).have.keys(["a", "b"]) }, { actual: {a: 1}, expected: ["a", "b"], message: "{\"a\":1} must have keys [\"a\",\"b\"]" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must({a: 1, b: 2}).not.have.keys(["a", "b"]) }) }) }) }) js-must-0.13.4/test/must/least_test.js000066400000000000000000000013341303625023100176510ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe(".prototype.least", function() { it("must pass if above", function() { assert.pass(function() { Must(69).be.at.least(42) }) }) it("must pass if equal", function() { assert.pass(function() { Must(69).be.at.least(69) }) }) it("must fail if below", function() { assert.fail(function() { Must(69).be.at.least(1337) }) }) require("./_assertion_error_test")(function() { Must(42).be.at.least(69) }, { actual: 42, expected: 69, message: "42 must be at least 69" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(69).not.be.at.least(42) }) }) }) }) js-must-0.13.4/test/must/length_test.js000066400000000000000000000020251303625023100200200ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.length", function() { describe("given String", function() { it("must pass if length equal", function() { assert.pass(function() { Must("hello").have.length(5) }) }) it("must fail if length not equal", function() { assert.fail(function() { Must("hello").have.length(42) }) }) }) describe("given Array", function() { it("must pass if length equal", function() { assert.pass(function() { Must([1, 2, 3, 4]).have.length(4) }) }) it("must fail if length not equal", function() { assert.fail(function() { Must([1, 2, 3, 4]).have.length(42) }) }) }) require("./_assertion_error_test")(function() { Must("hello").have.length(42) }, { actual: "hello", expected: 42, message: "\"hello\" must have length of 42" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must("hello").not.have.length(5) }) }) }) }) js-must-0.13.4/test/must/lt_test.js000066400000000000000000000003571303625023100171640ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.lt", function() { it("must be an alias of Must.prototype.below", function() { assert.strictEqual(Must.prototype.lt, Must.prototype.below) }) }) js-must-0.13.4/test/must/lte_test.js000066400000000000000000000003571303625023100173310ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.lte", function() { it("must be an alias of Must.prototype.most", function() { assert.strictEqual(Must.prototype.lte, Must.prototype.most) }) }) js-must-0.13.4/test/must/match_test.js000066400000000000000000000042701303625023100176370ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.match", function() { // Allow using new String: /* jshint -W053 */ /* eslint no-new-wrappers: 0 */ describe("given String and RegExp", function() { var primitive = "Year 2014 might be like 1984." var object = new String(primitive) it("must pass if given string primitive matches", function() { assert.pass(function() { Must(primitive).match(/^Year \d+ might/) }) }) it("must fail if given string primitive does not match", function() { assert.fail(function() { Must(primitive).match(/^\d+ might/) }) }) it("must pass if given string object matches", function() { assert.pass(function() { Must(object).match(/^Year \d+ might/) }) }) it("must fail if given string object does not match", function() { assert.fail(function() { Must(object).match(/^\d+ might/) }) }) }) describe("given String and String", function() { var primitive = "Year 2014 might be like 1984." var object = new String(primitive) it("must pass if given string primitive matches", function() { assert.pass(function() {Must(primitive).match("^Year \\d+ might")}) }) it("must fail if given string primitive does not match", function() { assert.fail(function() { Must(primitive).match("^\\d+ might") }) }) it("must pass if given string object matches", function() { assert.pass(function() { Must(object).match("^Year \\d+ might") }) }) it("must fail if given string object does not match", function() { assert.fail(function() { Must(object).match("^\\d+ might") }) }) require("./_assertion_error_test")(function() { Must("1984").match("^2014$") }, { actual: "1984", expected: /^2014$/, message: "\"1984\" must match /^2014$/" }) }) require("./_assertion_error_test")(function() { Must("1984").match(/^2014$/) }, { actual: "1984", expected: /^2014$/, message: "\"1984\" must match /^2014$/" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must("1984").not.match(/^1984$/) }) }) }) }) js-must-0.13.4/test/must/most_test.js000066400000000000000000000013251303625023100175230ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe(".prototype.most", function() { it("must pass if below", function() { assert.pass(function() { Must(42).be.at.most(69) }) }) it("must pass if equal", function() { assert.pass(function() { Must(69).be.at.most(69) }) }) it("must fail if above", function() { assert.fail(function() { Must(1337).be.at.most(69) }) }) require("./_assertion_error_test")(function() { Must(69).be.at.most(42) }, { actual: 69, expected: 42, message: "69 must be at most 42" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(42).not.be.at.most(69) }) }) }) }) js-must-0.13.4/test/must/must_test.js000066400000000000000000000003331303625023100175270ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.must", function() { it("must return self", function() { var must = Must(true) assert.strictEqual(must.must, must) }) }) js-must-0.13.4/test/must/nan_test.js000066400000000000000000000032221303625023100173130ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.null", function() { it("must fail given null", function() { assert.fail(function() { Must(null).be.nan() }) }) it("must fail given undefined", function() { assert.fail(function() { Must(undefined).be.nan() }) }) it("must pass given NaN", function() { assert.pass(function() { Must(NaN).be.nan() }) }) it("must fail given another number", function() { assert.fail(function() { Must(42).be.nan() }) }) it("must fail given a string of NaN", function() { assert.fail(function() { Must("NaN").be.nan() }) }) it("must fail given a string of a number", function() { assert.fail(function() { Must("42").be.nan() }) }) describe("AssertionError", function() { function test() { Must(42).be.nan() } it("must be thrown", function() { assert.throws(test, Must.AssertionError) }) // Can't test NaNs with strictEqual, sadly. it("must have all properties", function() { try { test() } catch (ex) { assert.strictEqual(ex.actual, 42) assert(isNaN(ex.expected)) assert.strictEqual(ex.message, "42 must be NaN") } }) it("must have correct stack trace", function() { try { test() } catch (ex) { var stack = ex.stack.split(/\r?\n/) assert(stack[0].match(/AssertionError/, "must include AssertionError")) assert(stack[1].match(/[\\\/]test[\\\/]/), "must have test at top") } }) }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(NaN).not.be.nan() }) }) }) }) js-must-0.13.4/test/must/nonenumerable_property_test.js000066400000000000000000000005131303625023100233350ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.nonenumerableProperty", function() { it("must be an alias of Must.prototype.nonenumerable", function() { var nonenumerable = Must.prototype.nonenumerable assert.strictEqual(Must.prototype.nonenumerableProperty, nonenumerable) }) }) js-must-0.13.4/test/must/nonenumerable_test.js000066400000000000000000000001551303625023100213730ustar00rootroot00000000000000describe(".prototype.nonenumerable", function() { require("./_enumerable_test")("nonenumerable", false) }) js-must-0.13.4/test/must/not_test.js000066400000000000000000000014321303625023100173400ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.not", function() { it("must return an instance of Must", function() { assert(Must(true).not instanceof Must) }) it("must invert condition", function() { assert.pass(function() { Must(false).not.equal(true) }) }) it("must invert condition multiple times", function() { assert.pass(function() { Must(true).not.not.equal(true) }) }) it("must not modify existing instance of Must", function() { var must = Must(true) assert.fail(function() { must.not.equal(true) }) assert.pass(function() { must.equal(true) }) }) it("must inherit from existing instance", function() { var must = Must(true) assert.strictEqual(Object.getPrototypeOf(must.not), must) }) }) js-must-0.13.4/test/must/null_test.js000066400000000000000000000021041303625023100175070ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.null", function() { it("must pass given null", function() { assert.pass(function() { Must(null).be.null() }) }) it("must fail given true primitive", function() { assert.fail(function() { Must(true).be.null() }) }) it("must fail given false primitive", function() { assert.fail(function() { Must(false).be.null() }) }) it("must fail given undefined", function() { assert.fail(function() { Must(undefined).be.null() }) }) it("must fail given empty string", function() { assert.fail(function() { Must("").be.null() }) }) it("must not do anything when not called as a function", function() { assert.pass(function() { void Must(null).be.null }) }) require("./_assertion_error_test")(function() { Must(true).be.null() }, { actual: true, expected: null, message: "true must be null" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(null).not.be.null() }) }) }) }) js-must-0.13.4/test/must/number_test.js000066400000000000000000000026151303625023100200340ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.number", function() { // Allow using new Number: /* jshint -W053 */ /* eslint no-new-wrappers: 0 */ it("must fail given null", function() { assert.fail(function() { Must(null).be.number() }) }) it("must fail given undefined", function() { assert.fail(function() { Must(undefined).be.number() }) }) it("must fail given boolean primitive", function() { assert.fail(function() { Must(true).be.date() }) assert.fail(function() { Must(false).be.date() }) }) it("must pass given number primitive", function() { assert.pass(function() { Must(42).be.number() }) }) it("must fail given number object", function() { assert.fail(function() { Must(new Number(42)).be.number() }) }) it("must fail given string primitive", function() { assert.fail(function() { Must("").be.number() }) }) it("must fail given array", function() { assert.fail(function() { Must([]).be.number() }) }) it("must fail given object", function() { assert.fail(function() { Must({}).be.number() }) }) require("./_assertion_error_test")(function() { Must("").be.number() }, { actual: "", message: "\"\" must be a number" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(42).not.be.number() }) }) }) }) js-must-0.13.4/test/must/object_test.js000066400000000000000000000023001303625023100200010ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.object", function() { it("must pass given object", function() { assert.pass(function() { Must({}).be.object() }) }) it("must fail given null", function() { assert.fail(function() { Must(null).be.object() }) }) it("must fail given undefined", function() { assert.fail(function() { Must(undefined).be.object() }) }) it("must fail given boolean primitive", function() { assert.fail(function() { Must(true).be.object() }) assert.fail(function() { Must(false).be.object() }) }) it("must fail given number primitive", function() { assert.fail(function() { Must(0).be.object() }) }) it("must fail given string primitive", function() { assert.fail(function() { Must("").be.object() }) }) it("must pass given array", function() { assert.pass(function() { Must([]).be.object() }) }) require("./_assertion_error_test")(function() { Must(42).be.object() }, { actual: 42, message: "42 must be an object" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must({}).not.be.object() }) }) }) }) js-must-0.13.4/test/must/own_keys_test.js000066400000000000000000000010541303625023100203760ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.ownKeys", function() { require("./_keys_test")("ownKeys", false) require("./_assertion_error_test")(function() { Must({a: 1}).have.ownKeys(["a", "b"]) }, { actual: {a: 1}, expected: ["a", "b"], message: "{\"a\":1} must have own keys [\"a\",\"b\"]" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must({a: 1, b: 2}).not.have.ownKeys(["a", "b"]) }) }) }) }) js-must-0.13.4/test/must/own_properties_test.js000066400000000000000000000001611303625023100216150ustar00rootroot00000000000000describe("Must.prototype.ownProperties", function() { require("./_properties_test")("ownProperties", false) }) js-must-0.13.4/test/must/own_property_test.js000066400000000000000000000005411303625023100213070ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe(".prototype.ownProperty", function() { require("./_property_test")("ownProperty", false) it("must pass if object has property named hasOwnProperty", function() { assert.pass(function() { Must({hasOwnProperty: false}).have.ownProperty("hasOwnProperty") }) }) }) js-must-0.13.4/test/must/own_test.js000066400000000000000000000003751303625023100173500ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.own", function() { it("must be an alias of Must.prototype.ownProperty", function() { assert.strictEqual(Must.prototype.own, Must.prototype.ownProperty) }) }) js-must-0.13.4/test/must/permutation_of_test.js000066400000000000000000000030531303625023100215740ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.permutationOf", function() { it("must pass if given array has same members", function() { assert.pass(function() { Must([1, 2, 3]).be.a.permutationOf([3, 2, 1]) }) }) it("must fail if given array does not have same members", function() { assert.fail(function() { Must([1, 2, 3]).be.a.permutationOf([1]) }) }) it("must fail if given array is missing duplicated members", function() { assert.fail(function() { Must([1, 2]).be.a.permutationOf([2, 1, 1]) }) }) it("must fail if given array has extra duplicated members", function() { assert.fail(function() { Must([1, 1, 2]).be.a.permutationOf([2, 1]) }) }) it("must pass if given array has same duplicated members", function() { assert.pass(function() { Must([1, 1, 2]).be.a.permutationOf([2, 1, 1]) }) }) it("must pass if both arrays empty", function() { assert.pass(function() { Must([]).be.a.permutationOf([]) }) }) it("must fail if given array has member of different type", function() { assert.fail(function() { Must([1]).be.a.permutationOf(["1"]) }) }) require("./_assertion_error_test")(function() { Must([1, 2, 3]).be.a.permutationOf([1, 2]) }, { actual: [1, 2, 3], expected: [1, 2], diffable: true, message: "[1,2,3] must be a permutation of [1,2]" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must([1, 2, 3]).not.be.a.permutationOf([1, 2, 3]) }) }) }) }) js-must-0.13.4/test/must/properties_test.js000066400000000000000000000001521303625023100207320ustar00rootroot00000000000000describe("Must.prototype.properties", function() { require("./_properties_test")("properties", true) }) js-must-0.13.4/test/must/property_test.js000066400000000000000000000001441303625023100204230ustar00rootroot00000000000000describe("Must.prototype.property", function() { require("./_property_test")("property", true) }) js-must-0.13.4/test/must/regexp_test.js000066400000000000000000000024701303625023100200350ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.regexp", function() { it("must fail given null", function() { assert.fail(function() { Must(null).be.regexp() }) }) it("must fail given undefined", function() { assert.fail(function() { Must(undefined).be.regexp() }) }) it("must fail given boolean primitive", function() { assert.fail(function() { Must(true).be.regexp() }) assert.fail(function() { Must(false).be.regexp() }) }) it("must fail given number primitive", function() { assert.fail(function() { Must(0).be.regexp() }) }) it("must fail given string primitive", function() { assert.fail(function() { Must("").be.regexp() }) }) it("must fail given array", function() { assert.fail(function() { Must([]).be.regexp() }) }) it("must fail given object", function() { assert.fail(function() { Must({}).be.regexp() }) }) it("must pass given a regexp", function() { assert.pass(function() { Must(/.*/).be.regexp() }) }) require("./_assertion_error_test")(function() { Must(42).be.regexp() }, { actual: 42, message: "42 must be a regular expression" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(/.*/).not.be.regexp() }) }) }) }) js-must-0.13.4/test/must/reject_test.js000066400000000000000000000041451303625023100200200ustar00rootroot00000000000000var Promise = global.Promise || require("promise") var Must = require("../..") var assert = require("./assert") describe("Must.prototype.reject", function() { it("must return a promise from a matcher", function() { var promise = Must(Promise.resolve(42)).reject.number() assert.strictEqual(typeof promise.then, "function") }) it("must resolve given a rejected promise with expected value", function() { return Must(Promise.reject(42)).reject.equal(42) }) it("must reject given a resolved promise", function() { return Must(Promise.resolve(42)).reject.equal(42).then(raise, assertThrown) }) it("must not change existing instance before resolving", function() { var must = Must(Promise.reject(42)) must.reject.equal(42) assert.fail(function() { must.equal(42) }) }) it("must not change existing instance after resolving", function() { var must = Must(Promise.reject(42)) var promise = must.reject.equal(42) return promise.then(function() { must.be.an.instanceof(Promise) }) }) describe("AssertionError", function() { function test() { return Must(Promise.reject(13)).reject.equal(42) } it("must be rejected", function() { return test().then(raise, assertThrown) }) it("must have all properties", function() { return test().then(raise, function(err) { assert.deepEqual(err, { actual: 13, expected: 42, message: "13 must equal 42" }) }) }) it("must have correct stack trace", function() { return test().then(raise, function(err) { var stack = err.stack.split(/\r?\n/) assert(stack[0].match(/AssertionError/, "must include AssertionError")) assert(stack[1].match(/[\\\/]test[\\\/]/), "must have test at top") }) }) }) describe(".not", function() { it("must invert the assertion", function() { var promise = Must(Promise.reject(42)).reject.not.equal(42) return promise.then(raise, assertThrown) }) }) }) function assertThrown(err) { assert(err instanceof Must.AssertionError) } function raise() { throw new Error("Must fail") } js-must-0.13.4/test/must/resolve_test.js000066400000000000000000000037371303625023100202310ustar00rootroot00000000000000var Promise = global.Promise || require("promise") var Must = require("../..") var assert = require("./assert") describe("Must.prototype.resolve", function() { it("must return a promise from a matcher", function() { var promise = Must(Promise.resolve(42)).resolve.number() assert.strictEqual(typeof promise.then, "function") }) it("must resolve given a resolved promise with expected value", function() { return Must(Promise.resolve(42)).resolve.equal(42) }) it("must not change existing instance before resolving", function() { var must = Must(Promise.resolve(42)) must.resolve.equal(42) assert.fail(function() { must.equal(42) }) }) it("must not change existing instance after resolving", function() { var must = Must(Promise.resolve(42)) var promise = must.resolve.equal(42) return promise.then(function() { must.be.an.instanceof(Promise) }) }) describe("AssertionError", function() { function test() { return Must(Promise.resolve(13)).resolve.equal(42) } it("must be rejected", function() { return test().then(raise, assertThrown) }) it("must have all properties", function() { return test().then(raise, function(err) { assert.deepEqual(err, { actual: 13, expected: 42, message: "13 must equal 42" }) }) }) it("must have correct stack trace", function() { return test().then(raise, function(err) { var stack = err.stack.split(/\r?\n/) assert(stack[0].match(/AssertionError/, "must include AssertionError")) assert(stack[1].match(/[\\/]test[\\/]/), "must have test at top") }) }) }) describe(".not", function() { it("must invert the assertion", function() { var promise = Must(Promise.resolve(42)).resolve.not.equal(42) return promise.then(raise, assertThrown) }) }) }) function assertThrown(err) { assert(err instanceof Must.AssertionError) } function raise() { throw new Error("Must fail") } js-must-0.13.4/test/must/start_with_test.js000066400000000000000000000024671303625023100207410ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.startWith", function() { describe("given string", function() { it("must pass if string starts with given shorter string", function() { assert.pass(function() { Must("Hello, John").startWith("Hello") }) }) it("must fail if string does not start with given shorter string", function() { assert.fail(function() { Must("Hello, John").startWith("Bye") }) }) it("must fail if string ends with given shorter string", function() { assert.fail(function() { Must("Hello, John").startWith("John") }) }) it("must fail if string contains given string", function() { assert.fail(function() { Must("Hello").startWith("l") }) }) it("must fail given a longer string", function() { assert.fail(function() { Must("Hello").startWith("John, Hello") }) assert.fail(function() { Must("Hello").startWith("Hello, John") }) }) }) require("./_assertion_error_test")(function() { Must("Hello").startWith("Bye") }, { actual: "Hello", expected: "Bye", message: "\"Hello\" must start with \"Bye\"" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must("Hello").not.startWith("He") }) }) }) }) js-must-0.13.4/test/must/string_test.js000066400000000000000000000026121303625023100200470ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.string", function() { // Allow using new String: /* jshint -W053 */ /* eslint no-new-wrappers: 0 */ it("must fail given null", function() { assert.fail(function() { Must(null).be.string() }) }) it("must fail given undefined", function() { assert.fail(function() { Must(undefined).be.string() }) }) it("must fail given boolean primitive", function() { assert.fail(function() { Must(true).be.date() }) assert.fail(function() { Must(false).be.date() }) }) it("must fail given number primitive", function() { assert.fail(function() { Must(0).be.string() }) }) it("must pass given string primitive", function() { assert.pass(function() { Must("").be.string() }) }) it("must fail given string object", function() { assert.fail(function() { Must(new String("")).be.string() }) }) it("must fail given array", function() { assert.fail(function() { Must([]).be.string() }) }) it("must fail given object", function() { assert.fail(function() { Must({}).be.string() }) }) require("./_assertion_error_test")(function() { Must(42).be.string() }, { actual: 42, message: "42 must be a string" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must("").not.be.string() }) }) }) }) js-must-0.13.4/test/must/symbol_test.js000066400000000000000000000026001303625023100200430ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") var describeSymbol = typeof Symbol != "undefined" ? describe : xdescribe describeSymbol("Must.prototype.symbol", function() { it("must fail given null", function() { assert.fail(function() { Must(null).be.symbol() }) }) it("must fail given undefined", function() { assert.fail(function() { Must(undefined).be.symbol() }) }) it("must fail given boolean primitive", function() { assert.fail(function() { Must(true).be.date() }) assert.fail(function() { Must(false).be.date() }) }) it("must pass given symbol", function() { assert.pass(function() { Must(Symbol()).be.symbol() }) }) it("must fail given number primitive", function() { assert.fail(function() { Must(42).be.symbol() }) }) it("must fail given string primitive", function() { assert.fail(function() { Must("").be.symbol() }) }) it("must fail given array", function() { assert.fail(function() { Must([]).be.symbol() }) }) it("must fail given object", function() { assert.fail(function() { Must({}).be.symbol() }) }) require("./_assertion_error_test")(function() { Must("").be.symbol() }, { actual: "", message: "\"\" must be a symbol" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(Symbol()).not.be.symbol() }) }) }) }) js-must-0.13.4/test/must/the_test.js000066400000000000000000000003311303625023100173150ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.the", function() { it("must return self", function() { var must = Must(true) assert.strictEqual(must.the, must) }) }) js-must-0.13.4/test/must/then_test.js000066400000000000000000000005451303625023100175020ustar00rootroot00000000000000var O = require("oolong") var Must = require("../..") var assert = require("./assert") describe("Must.prototype.then", function() { it("must be an alias of Must.prototype.resolve", function() { var then = O.lookupGetter(Must.prototype, "then") var resolve = O.lookupGetter(Must.prototype, "resolve") assert.strictEqual(then, resolve) }) }) js-must-0.13.4/test/must/throw_test.js000066400000000000000000000077751303625023100177230ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.throw", function() { /* eslint no-throw-literal: 0 */ require("./_error_test")("throw", function(err) { return function() { throw err } }) it("must invoke function in no context", function() { "use strict" var context Must(function() { context = this }).not.throw() assert.strictEqual(context, null) }) describe("given nothing", function() { it("must pass if function throws", function() { assert.pass(function() { Must(function() { throw 5 }).throw() }) }) it("must pass even if function throws undefined", function() { assert.pass(function() { Must(function() { throw undefined }).throw() }) }) it("must fail if function does not throw", function() { assert.fail(function() { Must(noop).throw() }) }) function noThrower() { void 42 } require("./_assertion_error_test")(function() { Must(noThrower).throw() }, { actual: undefined, message: "function noThrower() { void 42 } must throw" }) }) describe("given null", function() { it("must pass if function throws null", function() { assert.pass(function() { Must(function() { throw null }).throw(null) }) }) it("must fail if function throws undefined", function() { assert.fail(function() { Must(function() { throw undefined }).throw(null) }) }) it("must fail if function does not throw", function() { assert.fail(function() { Must(noop).throw(null) }) }) }) describe("given undefined", function() { it("must pass if function throws undefined", function() { assert.pass(function() { Must(function() { throw undefined }).throw(undefined) }) }) it("must fail if function throws null", function() { assert.fail(function() { Must(function() { throw null }).throw(undefined) }) }) it("must fail if function does not throw", function() { assert.fail(function() { Must(noop).throw(undefined) }) }) }) describe("given String", function() { function stringThrower() { throw "Oh no!" } it("must pass if function throws an identical string", function() { assert.pass(function() { Must(stringThrower).throw("Oh no!") }) }) it("must fail if function throws with part of identical string", function() { assert.fail(function() { Must(stringThrower).throw("Oh no") }) }) it("must fail if function throws an equivalent number", function() { assert.fail(function() { Must(function() { throw 42 }).throw("42") }) }) it("must fail if function throws an unequivalent string", function() { assert.fail(function() { Must(stringThrower).throw("Oh yes!") }) }) it("must fail if function does not throw", function() { assert.fail(function() { Must(noop).throw("Oh no!") }) }) function thrower() { throw "Nope!" } require("./_assertion_error_test")(function() { Must(thrower).throw("Oh no!") }, { actual: "Nope!", expected: "Oh no!", message: "function thrower() { throw \"Nope!\" } must throw \"Oh no!\"" }) }) describe("given RegExp", function() { function stringThrower() { throw "Oh no!" } it("must pass if function throws an matching string", function() { assert.pass(function() { Must(stringThrower).throw(/no!/) }) }) it("must fail if function throws an unmatching string", function() { assert.fail(function() { Must(stringThrower).throw(/yes!/) }) }) it("must fail if function does not throw", function() { assert.fail(function() { Must(noop).throw(/no!/) }) }) }) describe("given Function", function() { it("must fail if function does not throw", function() { assert.fail(function() { Must(noop).throw(Error) }) }) }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(function() { throw 42 }).not.throw() }) }) }) }) function noop() {} js-must-0.13.4/test/must/to_test.js000066400000000000000000000003271303625023100171640ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.to", function() { it("must return self", function() { var must = Must(true) assert.strictEqual(must.to, must) }) }) js-must-0.13.4/test/must/true_test.js000066400000000000000000000001331303625023100175140ustar00rootroot00000000000000describe("Must.prototype.true", function() { require("./_boolean_test")("true", true) }) js-must-0.13.4/test/must/truthy_test.js000066400000000000000000000001361303625023100200770ustar00rootroot00000000000000describe("Must.prototype.truthy", function() { require("./_truthy_test")("truthy", true) }) js-must-0.13.4/test/must/undefined_test.js000066400000000000000000000022051303625023100205000ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.undefined", function() { it("must pass given undefined", function() { assert.pass(function() { Must(undefined).be.undefined() }) }) it("must fail given true primitive", function() { assert.fail(function() { Must(true).be.undefined() }) }) it("must fail given false primitive", function() { assert.fail(function() { Must(false).be.undefined() }) }) it("must fail given null", function() { assert.fail(function() { Must(null).be.undefined() }) }) it("must fail given empty string", function() { assert.fail(function() { Must("").be.undefined() }) }) it("must not do anything when not called as a function", function() { assert.pass(function() { void Must(undefined).be.undefined }) }) require("./_assertion_error_test")(function() { Must(true).be.undefined() }, { actual: true, expected: undefined, message: "true must be undefined" }) describe(".not", function() { it("must invert the assertion", function() { assert.fail(function() { Must(undefined).not.be.undefined() }) }) }) }) js-must-0.13.4/test/must/with_test.js000066400000000000000000000003331303625023100175120ustar00rootroot00000000000000var Must = require("../..") var assert = require("./assert") describe("Must.prototype.with", function() { it("must return self", function() { var must = Must(true) assert.strictEqual(must.with, must) }) }) js-must-0.13.4/test/must_test.js000066400000000000000000000017641303625023100165500ustar00rootroot00000000000000// Bootstrapping with Assert ^_^: var Must = require("..") var assert = require("assert") describe("Must", function() { it("must return an instance of itself when called as a function", function() { assert(Must() instanceof Must) }) it("must have a constructor property", function() { assert.strictEqual(new Must().constructor, Must) }) it("must have constructor as a non-enumerable property", function() { var must = new Must for (var key in must) assert.notEqual(key, "constructor") }) it("must have name", function() { assert.strictEqual(Must.name, "Must") }) describe("new", function() { it("must return an instance of Must", function() { assert(new Must instanceof Must) }) describe("given message", function() { require("./must/_assertion_error_test")(function() { Must(false, "Negativity").true() }, { actual: false, expected: true, message: "Negativity: false must be true" }) }) }) }) js-must-0.13.4/test/register_test.js000066400000000000000000000057771303625023100174140ustar00rootroot00000000000000var Path = require("path") var Must var assert = require("assert") function reload() { // Reload to reset the fiddling we did here. delete require.cache[Path.resolve(__dirname, "../register.js")] Must = require("../register") } describe("Object.prototype.must", function() { beforeEach(reload) afterEach(function() { delete Object.prototype.must }) it("must exist", function() { assert(true.must) }) it("must return an instance of Must", function() { assert(true.must instanceof Must) }) it("must be deletable", function() { delete Object.prototype.must assert(!true.must) }) it("must be non-enumerable", function() { for (var key in this) assert.notEqual(key, "must") }) it("must be writable", function() { var obj = {} obj.must = 42 assert.strictEqual(obj.must, 42) }) describe("when called on", function() { // Allow using Boolean, Number, String as constructor in tests: /* jshint -W053 */ /* eslint no-new-wrappers: 0 */ it("must not box boolean", function() { assert.strictEqual(true.must.actual, true) }) it("must not box number", function() { assert.strictEqual((42).must.actual, 42) }) it("must not box string", function() { assert.strictEqual("foo".must.actual, "foo") }) it("must leave boxed boolean as-is", function() { var boolean = new Boolean(true) assert.strictEqual(boolean.must.actual, boolean) }) it("must leave boxed number as-is", function() { var number = new Number(42) assert.strictEqual(number.must.actual, number) }) it("must leave boxed string as-is", function() { var string = new String("hello") assert.strictEqual(string.must.actual, string) }) it("must not unbox date", function() { var date = new Date date.valueOf = function() {} assert.strictEqual(date.must.actual, date) }) it("must not unbox RegExp", function() { var regexp = new RegExp regexp.valueOf = function() {} assert.strictEqual(regexp.must.actual, regexp) }) it("must not unbox array", function() { var array = [] array.valueOf = function() {} assert.strictEqual(array.must.actual, array) }) it("must not unbox object", function() { var object = {} object.valueOf = function() {} assert.strictEqual(object.must.actual, object) }) it("must not unbox custom instance", function() { function Foo() {} Foo.prototype.valueOf = function() {} var foo = new Foo assert.strictEqual(foo.must.actual, foo) }) }) }) describe("Global.must", function() { /* global must */ beforeEach(reload) afterEach(function() { delete global.must }) it("must be an instance of Must by default", function() { assert(must instanceof Must) }) it("must be writable", function() { global.must = 42 assert.strictEqual(must, 42) }) it("must be writable to Must", function() { global.must = Must assert.strictEqual(must, Must) }) })