mirror of
https://github.com/google/pebble.git
synced 2025-03-15 08:41:21 +00:00
.. | ||
.eslintrc.js | ||
.gitignore | ||
package.json | ||
pebble-mock.js | ||
README.md | ||
test_message.js |
sdk/include/*.js unit testing how-to
This folder contains tests for the .js code in sdk/include.
Installing dependencies
cd sdk/tests/include
npm install
Running tests
cd sdk/tests/include
npm test
– this runs the tests using the mocha test runner.
You should see some output, similar to this:
$ npm test
> pebble-pkjs-tests@1.0.0 test /Users/martijn/tintin/sdk/tests/include
> NODE_PATH=../include ./node_modules/mocha/bin/mocha *.js
Pebble
interprets received postMessage API data as UTF-8
✓ interprets [34,34] as ""
✓ interprets [34,240,159,146,169,34] as "💩"
✓ interprets [34,237,160,181,237,188,128,34] as {}
✓ interprets [34,196,145,34] as "đ"
✓ interprets [34,224,160,149,34] as "ࠕ"
encodes sent postMessage API data as UTF-8
sendAppMessage: [object Object]
✓ encodes "" as [34,34,0]
sendAppMessage: [object Object]
✓ encodes "💩" as [34,240,159,146,169,34,0]
sendAppMessage: [object Object]
✓ encodes "đ" as [34,196,145,34,0]
sendAppMessage: [object Object]
✓ encodes "ࠕ" as [34,224,160,149,34,0]
9 passing (25ms)
Linting the test code
cd sdk/tests/include
npm run-script lint
Adding tests
- You can add
test_xyz.js
files in thetests
folder. It will automatically get picked up by the test runner. - If you need to a mock for the global
Pebble
object, check outpebble-mock.js
. It's probably worth using and extending that than to re-invent the wheel. - When adding additional dependencies (node packages), make sure to install them using
npm install --save-dev <PACKAGE_NAME>
so that they get added to thedevDependencies
in thepackage.json
file.