c-style assert() for nodejs, reporting the expression string as the error message
JavaScript HTML
Pull request Compare This branch is 9 commits ahead, 2 commits behind tj:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
.npmignore
LICENSE
Readme.md
better-assert-browser.js
better-assert-node.js
browser-test.html better-assert-browser!! Jun 30, 2016
browser-test.js Final changes Jul 1, 2016
package.json

Readme.md

better-assert-browser

Better c-style assertions using for self-documenting failure messages IN THE BUHROWZA.

Installation

npm install devinrhode2/better-assert-browser --save-dev

Then include node_modules/better-assert-browser/better-assert-browser.js in your page. You could also copy and paste the code from this repo, nobody's watching.

Example

By default assertions are enabled, however setting window.NO_ASSERT to true will deactivate them.

try {
  console.log('before calling assert')
  assert('truthy')
  console.log('called assert')
  assert(window.someFoo === 'bar')
  console.log('called with false')
} catch (e) {
  console.error('assert() failed:'+e.stack)
}

This library/function is dependent upon the v8/chrome stacktrace api.

To get stacktraces for failed assertions, you need to check "Async" in the right sidebar of the chrome devtools sources pane

This is because this function makes a request for the javascript file at the file url indicated in the stack trace using window.fetch, which returns a promise, inside this we throw an assertion error with the code asserted.

This library won't work unless your server responds to requests for individual files.

Contributing

hub clone devinrhode2/better-assert-browser # brew install hub if u kno foo
cd better-assert-browser
npm install -g live-server
live-server

Open up http://127.0.0.1:8080/browser-test.html

You should then be able to open better-assert-browser.js and browser-test.js in chrome devtools sources pane, hit esc to show the console, and livedit

MIT License, see LICENSE file